0

I am fairly new to hibernate and this is very strange - I am trying to run a Spring-Hibernate rest application on tomcat using eclipse. I have an entity defined as below -

@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 version is as below -

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

With this, If I run the application , it throws exception as below -

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

The sequence bdp_billing_rec_ref_id_seq exists in database, I have made it sure. After googling the issue, according to suggestions I modified the GenerationType.AUTO to GenerationType.IDENTITY , and it worked . The Web Server started to run.

Now, the application tries to insert rows in to BillingRecordReference table after hitting a rest endpoint. At this moment, hibernate throw another exception and values did not inserted in to table.

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

The oracle version is 12c, I am running JAVA - openjdk version "1.8.0_181-1-ojdkbuild", Tomcat Version is 8.0.5.

Please suggest what could be wrong here ?

4
  • Did you tried change strategy to GenerationType.SEQUENCE? And add unique = true, updatable = false, nullable = false to @Column(...) Commented Dec 12, 2019 at 12:35
  • GenerationType.IDENTITY requires the column to be a actual identity column to work. And as its the primary key, the value is not allowed to be null, which it is when inserting with identity column Commented Dec 12, 2019 at 12:37
  • @Dumbo yes sir, i did changed to Generation type.SEQUENCE , In this case , exception was - missing sequence Commented Dec 12, 2019 at 13:29
  • try native query annotation @Query(value = "SELECT seq_name.nextval FROM dual", nativeQuery = true) Commented Dec 13, 2019 at 10:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.