我定義的實體與生成的ID值,但是當我嘗試做一個插入我得到這個錯誤:JPA:與Oracle數據庫自動遞增ID
10:33:32,202 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-8) SQL Error: 2289, SQLState: 42000
10:33:32,203 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-8) ORA-02289: sequence does not exist
10:33:32,205 ERROR [org.jboss.as.ejb3.invocation] (default task-8) WFLYEJB0034: EJB Invocation failed on component javax.ejb.EJBTransactionRolledbackException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
Caused by: java.sql.SQLSyntaxErrorException: ORA-02289: sequence does not exist
實體:
@Entity
@Table(name = "TYPEDEM")
public class TypeDem {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "ID")
private long id;
@Column(name = "CODE")
private String code;
@Column(name = "LABEL")
..
}
Claass:
@Override
public TypeDem save(TypeDem typeDem) {
entityManager.persist(typeDem);
return typeOfDemand;
}
在調試,我看到id的值是空
請參閱https://stackoverflow.com/questions/20603638/what-is-the-use-of-annotations-id-and-generatedvaluestrategy-generationtype –
不,Oracle沒有「自動增量」支持,所以不,你不能使用IDENTITY策略。然而,我會期待你的JPA提供者告訴你,而不是僅僅使用NULL!也許你應該提出一個錯誤。 –
你想用來生成id的序列是什麼。是否在您的數據庫架構 –