我定义了一个具有生成的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的值为空
发布于 2017-08-14 16:46:09
标识生成器
在Sybase、My SQL、MS SQL Server、DB2和HypersonicSQL中使用它来支持id列。返回的id类型为short、int或long。
以下各项支持身份类型(包含在SQL:2003标准中):
SQL Server MySQL (AUTO_INCREMENT) DB2 HSQLDB标识生成器允许整数/bigint列按需自动递增。增量过程发生在当前运行的事务之外,因此回滚可能会丢弃已经分配的值(可能会出现值间隙)。
对于Oracle,请使用以下代码@GeneratedValue(strategy=GenerationType.AUTO)
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "ID")发布于 2017-08-14 16:53:50
您的解决方案是正确的。
唯一的问题似乎是hibernate.hbm2ddl.auto没有设置为更新,请使用更新。使用create或create-drop时要非常小心。
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
Caused by: java.sql.SQLSyntaxErrorException: ORA-02289: sequence does not exist这清楚地表明数据库中缺少该序列。
https://stackoverflow.com/questions/45670510
复制相似问题