-->
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.  [ 3 posts ] 
Author Message
 Post subject: ID field not appearing in insert statement
PostPosted: Wed Jan 21, 2009 1:03 pm 
Beginner
Beginner

Joined: Thu Apr 12, 2007 10:38 am
Posts: 22
Hi

I've got two columns mapped as my primary key. The values are generated by my application.

When I call entityManager.persist, the insert statement includes one of them but not the other, so I get a 'cant insert null' sort of error.

Here's my class


Code:
@Entity
@Table(name="bulk_account_log")
public class BulkAccountLog {

   private Long uploadId;
   private Long sequenceNo;

    /**
     * @return the uploadId
     */
    @Id
    @Column(name="upload_id")
    public Long getUploadId() {
        return uploadId;
    }

    /**
     * @param uploadId the uploadId to set
     */
    public void setUploadId(Long uploadId) {
        this.uploadId = uploadId;
    }

    /**
     * @return the sequenceNo
     */
    @Id
    public Long getSequenceNo() {
        return sequenceNo;
    }

    /**
     * @param sequenceNo the sequenceNo to set
     */
    public void setSequenceNo(Long sequenceNo) {
        this.sequenceNo = sequenceNo;
    }

}


I think it might be something to do with the GenerationType attribute for an ID, but even if it was, I dont understand why one of the columns (sequenceNo) appears in the insert statement, while uploadId doesnt (the only difference is the column mapping.

Any advice appreciated thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2009 1:13 pm 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
If you want to use composite-ids you either need an IdClass or an EmbeddedId.

Both solutions are explained at http://www.hibernate.org/hib_docs/annotations/reference/en/html_single/#entity-mapping-identifier.

An IdClass for your example would look like:
Code:
public class BulkAccountLogId {
   private Long uploadId;
   private Long sequenceNo;
   //Getters and Setters
}

Also you would have to annotate your Entity with @IdClass(BulkAccountLogId.class)

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2009 2:32 pm 
Beginner
Beginner

Joined: Thu Apr 12, 2007 10:38 am
Posts: 22
Nice one mmerder, thanks. I'll give it a try in the morning.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.