我試圖從休眠添加一個新用戶到火鳥數據庫的表Hibernate不使用火鳥序列,但嘗試使用,而不是
Session session = factory.openSession();
UserDetail user = new UserDetail();
user.setName("Mark");
user.setPassword("1234567");
user.setUserType(1L);
session.beginTransaction();
try {
session.persist(user);
session.getTransaction().commit();
} catch (Exception e) {
session.getTransaction().rollback();
} finally {
session.close();
}
和我的實體是
@Entity
@Table(name = "USER_DETAIL")
public class UserDetail
{
@Id
@Column(name = "ID", nullable = false)
@SequenceGenerator(name = "gen", sequenceName = "GEN_USER_DETAIL_ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "gen")
private Long id;
@Column(name = "TYPE_ID")
@NotNull
private Long userType;
@Column(name = "NAME")
@NotNull
@Size(min = UserDetailConstraint.MIN_USER_NAME, max = UserDetailConstraint.MAX_USER_NAME)
private String name;
@Column(name = "HASHED_PASSWORD")
@NotNull
@Size(min = UserDetailConstraint.MIN_PASSWORD, max = UserDetailConstraint.MAX_PASSWORD)
private String password;
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
public Long getUserType() { return userType; }
public void setUserType(Long userType) { this.userType = userType; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getPassword() { return password; }
public void setPassword(String password) { this.password = password; }
}
但是當Hibernate試圖通過發電機來獲取新的ID,它使用
select next_val as id_val from GEN_USER_DETAIL_ID with lock
但GEN_USER_DETAIL_ID
爲n一張桌子,它是一個序列。
所以程序有錯誤
WARN: HHH10001002: Using Hibernate built-in connection pool (not for
production use!)
апр 26, 2017 5:19:06 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [org.firebirdsql.jdbc.FBDriver] at URL [jdbc:firebirdsql://localhost:3050/warehouse]
апр 26, 2017 5:19:06 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=SYSDBA, password=****}
апр 26, 2017 5:19:06 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
апр 26, 2017 5:19:06 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 5 (min=1)
апр 26, 2017 5:19:06 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.FirebirdDialect
апр 26, 2017 5:19:06 PM org.hibernate.id.enhanced.SequenceStyleGenerator configure
INFO: HHH000107: Forcing table use for sequence-style generator due to pooled optimizer selection where db does not support pooled sequences
апр 26, 2017 5:19:07 PM org.hibernate.validator.internal.util.Version <clinit>
INFO: HV000001: Hibernate Validator 4.3.2.Final
Hibernate: select next_val as id_val from GEN_USER_DETAIL_ID with lock
апр 26, 2017 5:19:07 PM org.hibernate.id.enhanced.TableStructure$1$1 execute
ERROR: could not read a hi value
org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544569. Dynamic SQL Error
SQL error code = -204
Table unknown
GEN_USER_DETAIL_ID
At line 1, column 51
當我使用XML映射,而不是註釋,然後一切工作正常崩潰。
我該如何解決這個問題?
這是很重要的序列式發電機表使用強制由於彙集優化選擇其中db不支持合併的序列,你的數據庫是不支持Sequnce,你可以看看 – rajadilipkolli
@rajadilipkolli火鳥支持序列,只是不是合併序列。 –
如果您找到了解決方案,而不是解決方案,我建議您使用該解決方案發布自己的答案(並在超時後接受該答案)。 –