我正在使用以下字段注释:
@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
并添加 SQLCREATE SEQUENCE hibernate_sequence
一切正常(它是持久的),但我想使用该TABLE
策略将每个表序列保持在hibernate_sequences
.
我唯一的例外是TransactionRolledbackException
由于NullPointerException
集成测试中的测试失败引起的。没有明确说明它为什么不插入数据。
使用时我得到以下休眠输出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.conf
并log_statement = 'all'
签入pg_log
目录时,我看不到任何日志。所以我不确定如何启用该选项。
我还在使用 Arquillian、arquillian 持久性 API 和 JBoss 托管实例进行集成测试。我将更新标签,因为这可能与其中任何一个有关。