當我使用下面的字段註釋實體不被持久化:使用JPA
@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
。
我唯一的例外是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的管理實例進行集成測試。我將更新標籤,因爲這可能與任何這些標籤有關。的TableGenerator
是,基於事實並非如此,您正在做錯事。如果你想比這更多,你需要證明你的代碼和配置,以及你可能會得到任何錯誤的多很多。最好提供[SSCCE](http://sscce.org/)。 – 2013-03-03 05:49:07
您是否創建了實體?你堅持了嗎?我們看不到這些。你也應該讓'PostgreSQL中log_statement'然後檢查報表和錯誤,可能是有關PostgreSQL的日誌文件。確保你的代碼不會吞下異常。 – 2013-03-03 12:05:10
@RyanStewart我認爲這是隱含的「我在做錯上面的代碼嗎?」。 @CraigRinger我會編輯我的文章解釋一點點,我只是認爲這部分代碼可能有錯誤,因爲如果我將策略更改爲「SEQUENCE」,一切正常。 – 2013-03-03 15:32:52