1 Reply Latest reply: May 4, 2012 4:51 PM by cyril nestor RSS

@Audited issue when deleting record

cyril nestor Newbie

I posted this issue in the wrong hibernate forum (hibernate users), therefore I post it again at the right place.

 

I have the following error when I delete a record in a table.

(Extract from the log file)

Code:

...
delete
        from
            custom_question
        where
            question_id=?
.....
insert
        into
            custom_question_AUD
            (REVTYPE, question_answers, question_number, question_text, question_type, required, enroll_id, question_id, REV)
        values
            (?, ?, ?, ?, ?, ?, ?, ?, ?)

2012-05-04 10:04:34,619 TRACE [org.hibernate.type.StringType] (http-BIO213%2F192.168.2.151-443-7) binding null to parameter: 2

2012-05-04 10:04:34,619 TRACE [org.hibernate.type.LongType] (http-BIO213%2F192.168.2.151-443-7) binding null to parameter: 3

2012-05-04 10:04:34,619 TRACE [org.hibernate.type.StringType] (http-BIO213%2F192.168.2.151-443-7) binding null to parameter: 4

2012-05-04 10:04:34,619 TRACE [org.hibernate.type.StringType] (http-BIO213%2F192.168.2.151-443-7) binding null to parameter: 5

2012-05-04 10:04:34,619 TRACE [org.hibernate.type.CharacterType] (http-BIO213%2F192.168.2.151-443-7) binding null to parameter: 6

2012-05-04 10:04:34,619 TRACE [org.hibernate.type.LongType] (http-BIO213%2F192.168.2.151-443-7) binding null to parameter: 7

2012-05-04 10:04:34,619 TRACE [org.hibernate.type.LongType] (http-BIO213%2F192.168.2.151-443-7) binding '8390' to parameter: 8

2012-05-04 10:04:34,619 TRACE [org.hibernate.type.IntegerType] (http-BIO213%2F192.168.2.151-443-7) binding '8581' to parameter: 9

 

 

ERROR [org.hibernate.util.JDBCExceptionReporter] (http-BIO213%2F192.168.2.151-443-4) ORA-01400: cannot insert NULL into ("FRAMEWK2"."CUSTOM_QUESTION_AUD"."ENROLL_ID")

 

 

 

 

 

My entity is the following:

Code:

@Entity
@Audited
@Table(name = "custom_question")
public class CustomQuestion implements Serializable {

 

   private static final long serialVersionUID = -3487942307494801788L;
   private long questionId;
   private EnrollInfo enrollInfo;
   private String questionText;
   private String questionType;
   private String questionAnswers;
   private long questionNumber;
   private Character required;

 

 

 

Here is the audit table definition:

Code:

CREATE TABLE "FRAMEWK2"."CUSTOM_QUESTION_AUD"
  (
    "QUESTION_ID"      NUMBER(19,0) NOT NULL ENABLE,
    "REV"              NUMBER(10,0) NOT NULL ENABLE,
    "REVTYPE"          NUMBER(3,0),
    "QUESTION_ANSWERS" VARCHAR2(255 CHAR),
    "QUESTION_TEXT"    VARCHAR2(255 CHAR),
    "QUESTION_TYPE"    VARCHAR2(255 CHAR),
    "ENROLL_ID"        NUMBER(19,0),
    "REQUIRED"         CHAR(1 BYTE),
    "QUESTION_NUMBER"  NUMBER(5,0),
    PRIMARY KEY ("ENROLL_ID", "REV") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" ENABLE,
    CONSTRAINT "CUSTOM_QUESTION_AUD_REV" FOREIGN KEY ("REV") REFERENCES "FRAMEWK2"."REVINFO" ("REV") ENABLE NOVALIDATE
  )
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
  (
    INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
  )
  TABLESPACE "USERS" ;

 

 

What am I doing wrong? The delete is fine but the auditing is visibly not working.

 

Thx for your help.

  • 1. Re: @Audited issue when deleting record
    cyril nestor Newbie

    Here is the solution to this issue.

    The CUSTOM_QUESTION_AUD table has been generated by Hibernate before I started working on this project. In the meantime the entity CUSTOM_QUESTION has been modified (primary key became QUESTION_ID instead of ENROLL_ID) but the schema has never been updated. Thus the table was out of sync with the entity. Since ENROLL_ID was the primary key it was indeed a non nullable field causing the following message:cannot insert NULL into ("FRAMEWK2"."CUSTOM_QUESTION_AUD"."ENROLL_ID")

    Once I altered the primary key to reflect the parent table everything worked fine.