Java 无法从JUnit访问HSQLDB表
我的问题是,我的单元测试失败了,因为我无法访问之前刚刚创建的表 从控制台的输出中,我可以看到执行了以下Hibernate命令Java 无法从JUnit访问HSQLDB表,java,hibernate,hsqldb,Java,Hibernate,Hsqldb,我的问题是,我的单元测试失败了,因为我无法访问之前刚刚创建的表 从控制台的输出中,我可以看到执行了以下Hibernate命令 Hibernate: alter table Server_Node drop constraint FK3621657E1249AF15 Hibernate: alter table Server_Node drop constraint FK3621657E2528B004 Hibernate: drop table EmailAccountSettings if e
Hibernate: alter table Server_Node drop constraint FK3621657E1249AF15
Hibernate: alter table Server_Node drop constraint FK3621657E2528B004
Hibernate: drop table EmailAccountSettings if exists
Hibernate: drop table Node if exists
Hibernate: drop table Server if exists
Hibernate: drop table Server_Node if exists
Hibernate: create table EmailAccountSettings (id varchar(255) generated by default as identity (start with 1), description varchar(255), name varchar(255), primary key (id))
Hibernate: create table Node (id bigint generated by default as identity (start with 1), name varchar(255), primary key (id), unique (name))
Hibernate: create table Server (id integer generated by default as identity (start with 1), name varchar(255), primary key (id), unique (name))
Hibernate: create table Server_Node (Server_id integer not null, nodes_id bigint not null, primary key (Server_id, nodes_id))
Hibernate: alter table Server_Node add constraint FK3621657E1249AF15 foreign key (nodes_id) references Node
Hibernate: alter table Server_Node add constraint FK3621657E2528B004 foreign key (Server_id) references Server
Hibernate: insert into Server (id, name) values (default, ?)
正如您所看到的,值被插入到表Server
中。但是下一个测试用例试图在表EmailAccountSettings
中插入一些内容,这将导致以下错误
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: user lacks privilege or object not found: EMAILACCOUNTSETTINGS
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1377)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1300)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:273)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
您知道该表有什么问题吗EmailAccountSettings
我使用Spring+Hibernate+HSQLDB+JUnit只是对涉及的组件进行概述。找到了这个问题的原因。再次查看表格创建语句时,灯突然亮了起来
Hibernate: create table EmailAccountSettings (id varchar(255) generated by default as identity (start with 1), description varchar(255), name varchar(255), primary key (id))
无法创建数据类型为varchar
的标识列。因此,声明没有成功。但在运行测试时,这在控制台中不可见
更改实体中的数据类型后,一切正常。找到了此问题的原因。再次查看表格创建语句时,灯突然亮了起来
Hibernate: create table EmailAccountSettings (id varchar(255) generated by default as identity (start with 1), description varchar(255), name varchar(255), primary key (id))
无法创建数据类型为varchar
的标识列。因此,声明没有成功。但在运行测试时,这在控制台中不可见
更改实体中的数据类型后,一切都按预期工作