1

次のフィールド注釈を使用しています。

@Id
@TableGenerator( name = "comment_sequence", pkColumnValue = "comment_sequence" )
@GeneratedValue( strategy = GenerationType.TABLE, generator = "comment_sequence" )
private Long id_comment;

テーブルを作成するためのSQLは次のとおりです。

CREATE TABLE hibernate_sequences ( sequence_name VARCHAR(255) NOT NULL, next_val bigint, PRIMARY KEY ( sequence_name ) );
INSERT INTO hibernate_sequences VALUES ( 'comment_sequence', 1 );

しかし、エンティティは永続的ではありません。何が起こっている可能性がありますか?上記のコードに何か問題がありますか?


編集:

元の投稿でいくつかの情報を抑制しました、申し訳ありません(ほとんど寝ている真夜中に尋ねられました=/)。

エンティティは適切に作成されています。戦略を変更しSEQUENCEて SQL を追加すると、CREATE SEQUENCE hibernate_sequenceすべてが正常に機能します (永続化されます)。ただし、TABLE戦略を使用して、各テーブル シーケンスhibernate_sequences

私が持っている唯一の例外は、統合テストでのテストの失敗が原因ですTransactionRolledbackExceptionNullPointerExceptionデータを挿入しない理由について明確な説明はありません。

を使用すると、次の休止状態の出力が得られますhibernate.show_sql = true

...

12:38:48,753 INFO  [stdout] (pool-5-thread-1) Hibernate: 
12:38:48,754 INFO  [stdout] (pool-5-thread-1)     insert 
12:38:48,755 INFO  [stdout] (pool-5-thread-1)     into
12:38:48,756 INFO  [stdout] (pool-5-thread-1)         cm_comment
12:38:48,757 INFO  [stdout] (pool-5-thread-1)         (cd_status, ds_message, dt_alt, dt_inc, id_user_alt, id_user_inc, id_problem, id_comment) 
12:38:48,758 INFO  [stdout] (pool-5-thread-1)     values
12:38:48,759 INFO  [stdout] (pool-5-thread-1)         (?, ?, ?, ?, ?, ?, ?, ?)

12:38:48,766 INFO  [stdout] (pool-5-thread-1) Hibernate: 
12:38:48,766 INFO  [stdout] (pool-5-thread-1)     select
12:38:48,767 INFO  [stdout] (pool-5-thread-1)         commentent0_.id_comment as id1_6_,
12:38:48,768 INFO  [stdout] (pool-5-thread-1)         commentent0_.cd_status as cd2_6_,
12:38:48,770 INFO  [stdout] (pool-5-thread-1)         commentent0_.ds_message as ds3_6_,
12:38:48,771 INFO  [stdout] (pool-5-thread-1)         commentent0_.dt_alt as dt4_6_,
12:38:48,772 INFO  [stdout] (pool-5-thread-1)         commentent0_.dt_inc as dt5_6_,
12:38:48,773 INFO  [stdout] (pool-5-thread-1)         commentent0_.id_user_alt as id6_6_,
12:38:48,774 INFO  [stdout] (pool-5-thread-1)         commentent0_.id_user_inc as id7_6_,
12:38:48,775 INFO  [stdout] (pool-5-thread-1)         commentent0_.id_problem as id8_6_ 
12:38:48,776 INFO  [stdout] (pool-5-thread-1)     from
12:38:48,777 INFO  [stdout] (pool-5-thread-1)         cm_comment commentent0_ 
12:38:48,778 INFO  [stdout] (pool-5-thread-1)     where
12:38:48,779 INFO  [stdout] (pool-5-thread-1)         commentent0_.id_problem=?

12:38:48,840 ERROR [org.jboss.arquillian.protocol.jmx.JMXTestRunner] (pool-5-thread-1) 
...

 java.lang.AssertionError: expected:<1> but was:<0>  

...

これが関連しているかどうかはわかりませんが、以前のテストでエラーが発生しました:

12:50:36,510 INFO [org.jboss.as.ejb3] (pool-4-thread-1) JBAS014101: Failed to find SFSB instance with session ID {[-98, -17, -32, -33, 63, 107, 74, 59, -76, -127, -19, 29, 24, 45, -50, 5]} in cache

アプリの実行後にディレクトリを変更postgresql.conflog_statement = 'all'てチェックインすると、ログが表示されません。pg_logそのため、そのオプションを有効にする方法がわかりません。

また、Arquillian、arquillian 永続化 API、および統合テスト用の JBoss マネージド インスタンスも使用しています。タグを更新します。これは、これらのいずれかに関連している可能性があるためです。

4

1 に答える 1

2

あなたの「宣言」にTableGeneratorは、どのテーブルを参照/使用するかについての情報が与えられていません。与えているのはpkColumn名だけです....

試す:

@TableGenerator( name = "comment_sequence", table = "hibernate_sequences", pkColumnName = "sequence_name", valueColumnName = "next_val", pkColumnValue = "comment_sequence", allocationSize=1)

allocationSize=1おそらく1よりも大きいはずです...動作していることを確認した場合。(アプリケーションが「大量の」エンティティを作成している場合、この戦略を使用してデータベース内の同じテーブルに多数のジェネレーターを配置する場合、潜在的なロックの問題に注意してください。)

于 2013-03-03T20:03:13.367 に答える