首页 > 解决方案 > HibernateException: Missing sequence or table and SQLIntegrityConstraintViolationException: ORA-01400: cannot insert NULL into

问题描述

我对hibernate相当陌生,这很奇怪-我正在尝试使用eclipse在tomcat上运行Spring-Hibernate rest应用程序。我有一个定义如下的实体 -

@Entity
@Table(name = "bdp_billing_rec_ref")
@NamedQueries(value = { @NamedQuery(name = BillingRecordReference.BILLING_RECORD_REF_DELETE_OLDER_THAN, query = "DELETE FROM BillingRecordReference WHERE updated<:date") })
public class BillingRecordReference {
  @Id
  @SequenceGenerator(name = "bdp_billing_rec_ref_id_seq_gen", sequenceName = "bdp_billing_rec_ref_id_seq")
  @GeneratedValue(strategy = GenerationType.AUTO, generator = "bdp_billing_rec_ref_id_seq_gen")
  @Column(name = "db_id")
  private Long dbId;

Oracle maven 依赖版本如下 -

    <dependency>
       <groupId>com.oracle</groupId>
       <artifactId>ojdbc6</artifactId>
       <scope>runtime</scope>
     </dependency>

有了这个,如果我运行应用程序,它会抛出如下异常 -

Caused by: org.hibernate.HibernateException: Missing sequence or table: bdp_billing_rec_ref_id_seq

该序列bdp_billing_rec_ref_id_seq存在于数据库中,我已经确定了。谷歌搜索问题后,根据建议,我将 GenerationType.AUTO 修改 GenerationType.IDENTITY 它起作用了。Web 服务器开始运行。

现在,应用程序在到达休息端点后尝试将行插入到 BillingRecordReference表中。此时,hibernate 抛出另一个异常并且值没有插入到表中。

java.sql.SQLIntegrityConstraintViolationException: ORA-01400: cannot insert NULL into ("DPOWNERA"."BDP_BILLING_REC_REF"."DB_ID")

oracle版本是12c,我运行的是JAVA-openjdk版本“1.8.0_181-1-ojdkbuild”,Tomcat版本是8.0.5。

请建议这里可能有什么问题?

标签: javaoraclehibernatedatabase-sequence

解决方案


推荐阅读