-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: ConstraintViolationException for a composite primary key
PostPosted: Thu Aug 19, 2010 6:30 pm 
Beginner
Beginner

Joined: Tue Feb 12, 2008 3:53 pm
Posts: 38
Hi,
I work on an application using JPA and oracle. I have a class with a composite primary key :

Code:
@Entity
@Table(schema = "ACCOUNT", name = "RLOGTRACE", uniqueConstraints = @UniqueConstraint(columnNames = {"LOG_DT", "LOG_USER_ID", "LOG_TYPE"}))
public class RLogtrace implements java.io.Serializable {


   private RLogtraceId id;

        @EmbeddedId
        public RLogtraceId getId() {
              return this.id;
        }
............
.............
............


and

Code:
@Embeddable
public class RLogtraceId implements java.io.Serializable {


   private Date logDt;
   private String logUserId;
   private Character logType;

   public RLogtraceId() {
   }

   public RLogtraceId(Date logDt, String logUserId, Character logType) {
      this.logDt = logDt;
      this.logUserId = logUserId;
      this.logType = logType;
   }

   @Column(name = "LOG_DT")
        @Temporal(TemporalType.TIMESTAMP)
   public Date getLogDt() {
      return this.logDt;
   }

   public void setLogDt(Date logDt) {
      this.logDt = logDt;
   }

   @Column(name = "LOG_USER_ID", length = 30)
   public String getLogUserId() {
      return this.logUserId;
   }

   public void setLogUserId(String logUserId) {
      this.logUserId = logUserId;
   }

   @Column(name = "LOG_TYPE", length = 1)
   public Character getLogType() {
      return this.logType;
   }
..........
}



with the table RLOGTRACE following :
Code:
CREATE TABLE "ACCOUNT"."RLOGTRACE"
  (
    "LOG_DT" DATE,
    "LOG_USER_ID"     VARCHAR2(30 BYTE),
    "LOG_TYPE"        CHAR(1 BYTE),
.....................
.....................
  )

  TABLESPACE "ACCOUNT" ;
COMMENT ON COLUMN "ACCOUNT"."R_LOGTRACE"."LOG_DT"
IS
  'Date and time of the logged event.';
  COMMENT ON COLUMN "ACCOUNT"."R_LOGTRACE"."LOG_USER_ID"
IS
  'Related user login.';
  COMMENT ON COLUMN "ACCOUNT"."R_LOGTRACE"."LOG_TYPE"
IS
  'TYPE OF event logged:
- I FOR login event,
- O FOR logout event,

CREATE UNIQUE INDEX "ACCOUNT"."PK_R_LOGTRACE" ON "ACCOUNT"."R_LOGTRACE"
  (
    "LOG_DT", "LOG_USER_ID", "LOG_TYPE"
  )



When I try to create with hibernate a RLogtrace object into the data base, I have this error :

Code:
JDBCExceptionReporter [ERROR] ORA-00001: unique constraint (ACCOUNT.PK_R_LOGTRACE) violated

2010-08-19 14:39:49 AbstractFlushingEventListener [ERROR] Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)


I don't see where is the error. Thank you for your answer


Top
 Profile  
 
 Post subject: Re: ConstraintViolationException for a composite primary key
PostPosted: Fri Aug 20, 2010 3:47 am 
Beginner
Beginner

Joined: Tue Feb 12, 2008 3:53 pm
Posts: 38
I forgot to give the insert method

Code:
public RLogtrace updateTraceLog(Character logType, String logUserId, String logError){
      RLogtraceId rLogtraceId = new RLogtraceId();
      rLogtraceId.setLogDt(new Date());
      rLogtraceId.setLogType(logType);
      rLogtraceId.setLogUserId(logUserId);     
      RLogtrace rLogTrace = new RLogtrace();
      rLogTrace.setId(rLogtraceId);
  .....................
      rLogTrace = (RLogtrace) rLogTraceDao.create(rLogTrace);
      return rLogTrace;
   }


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.