1

以前に作成したばかりのテーブルにアクセスできないという事実のために、単体テストが失敗するという問題があります。

コンソールの出力から、次の Hibernate コマンドが実行されていることがわかります。

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 を使用しています。

4

1 に答える 1

4

この問題の理由が見つかりました。テーブル作成ステートメントをもう一度見ると、突然ライトが点灯しました。

Hibernate: create table EmailAccountSettings (id varchar(255) generated by default as identity (start with 1), description varchar(255), name varchar(255), primary key (id))

datatype の ID 列を作成することはできませんvarchar。したがって、ステートメントは成功しませんでした。ただし、これはテストの実行時にコンソールに表示されません。

エンティティのデータ型を変更すると、すべてが期待どおりに機能します。

于 2013-01-11T13:24:00.500 に答える