【发布时间】:2018-01-22 01:20:09
【问题描述】:
我用 Generated 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")
..
}
类:
@Override
public TypeDem save(TypeDem typeDem) {
entityManager.persist(typeDem);
return typeOfDemand;
}
在debug中看到id的值为null
【问题讨论】:
-
不,Oracle 没有“自动增量”支持,所以不,你不能使用 IDENTITY 策略。但是,我希望您的 JPA 提供者会告诉您这一点,而不仅仅是使用 NULL!也许你应该提出一个错误。
-
你想用来生成id的序列是什么。它是在您的数据库架构中创建的