出于任何原因,控制台都会在日志下方显示在日志下方。如果 @ManyToOne已删除,控制台日志将清除,但应用程序加载正常且未显示任何错误。
在application.properties中设置DB,以在文件中创建(如果DB在内存中,则将得到相同的错误日志)。日志显示了正确的SQL,可以创建表,FK并插入新的预定义行(位于classpath:data.sql中)
我检查了不同的帖子,由于很多选择,似乎这个问题不容易解决。有什么建议么?谢谢。
不幸的是,Update 并不是表名。我更新为USER_ACCOUNT,但遇到相同的错误:用户缺少特权或找不到对象:PUBLIC.USER_ACCOUNT。它必须与注释@ManyToOne相关,因为当我删除它时,一切都会很好地加载
Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: PUBLIC.USER
at org.hsqldb.error.Error.error(Unknown Source) ~[hsqldb-2.4.1.jar:2.4.1]
at org.hsqldb.error.Error.error(Unknown Source) ~[hsqldb-2.4.1.jar:2.4.1]
at org.hsqldb.SchemaManager.getUserTable(Unknown Source) ~[hsqldb-2.4.1.jar:2.4.1]
at org.hsqldb.ParserDDL.compileAlterTable(Unknown Source) ~[hsqldb-2.4.1.jar:2.4.1]
at org.hsqldb.ParserDDL.compileAlter(Unknown Source) ~[hsqldb-2.4.1.jar:2.4.1]
at org.hsqldb.ParserCommand.compilePart(Unknown Source) ~[hsqldb-2.4.1.jar:2.4.1]
at org.hsqldb.ParserCommand.compileStatements(Unknown Source) ~[hsqldb-2.4.1.jar:2.4.1]
at org.hsqldb.Session.executeDirectStatement(Unknown Source) ~[hsqldb-2.4.1.jar:2.4.1]
at org.hsqldb.Session.execute(Unknown Source) ~[hsqldb-2.4.1.jar:2.4.1]
... 45 common frames omitted
用户实体
@Entity
@Table( name = "USER" )
@Getter @Setter
@ToString
@EqualsAndHashCode
public class User
{
@Id
@GeneratedValue( strategy = GenerationType.AUTO )
@Column( name = "USER_ID" )
private Integer id;
@Column( name = "USER_NAME", nullable = false )
private String userName;
@ManyToOne
@JoinColumn( name = "USER_STATUS_ID", referencedColumnName = "USER_STATUS_ID" , nullable = false )
private UserStatus status;
@ManyToOne
@JoinColumn( name = "USER_ROLE_ID", referencedColumnName = "USER_ROLE_ID", nullable = false )
private UserRole role;
@JsonIgnore
@Column( name = "PASSWORD", nullable = false )
private String password;
@Embedded
private Audit audit;
}
USerRole实体
@Entity
@Table( name = "USER_ROLE" )
@Getter @Setter
@ToString
@EqualsAndHashCode
public class UserRole
{
@Id
@Column( name = "USER_ROLE_ID" )
private Integer id;
@Column( name = "USER_ROLE" )
@Enumerated( EnumType.STRING )
private UserRoleEnum role;
}
HSQLDB.log
drop table user if exists
drop table user_role if exists
drop table user_status if exists
drop sequence hibernate_sequence if exists
create sequence hibernate_sequence start with 1 increment by 1
create table user (user_id integer not null, created_on date,
updated_on date, password varchar(255) not null, user_name
varchar(255) not null, user_role_id integer not null, user_status_id
integer not null, primary key (user_id))
create table user_role (user_role_id integer not null, user_role
varchar(255), primary key (user_role_id))
create table user_status (user_status_id integer not null,
user_status varchar(255), primary key (user_status_id))
alter table user add constraint FKh2wc2dtfdo8maylne7mgubowq foreign
key (user_role_id) references user_role
alter table user add constraint FKo6g0t5ih8a5bsioca8qh5ukg3 foreign
key (user_status_id) references user_status
INSERT INTO USER_STATUS VALUES(1,'PENDING_VERIFIED')
COMMIT
INSERT INTO USER_STATUS VALUES(2,'ACTIVE')
COMMIT
INSERT INTO USER_ROLE VALUES(1,'ADMIN')
COMMIT
INSERT INTO USER_ROLE VALUES(2,'USER')
提交
答案 0 :(得分:0)
您不能将“用户”用作表名,因为它是保留字。参见documentation
有两种解决方案。
1。将实体名称从“用户”更改为“用户”。
2。如果仍然要使用保留字,请使用反引号。
mysql> CREATE TABLE interval (begin INT, end INT);
ERROR 1064 (42000): You have an error in your SQL syntax.
near 'interval (begin INT, end INT)'
mysql> CREATE TABLE `interval` (begin INT, end INT);
Query OK, 0 rows affected (0.01 sec)
我建议您寻求第一种解决方案。