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: Two id in one entity not working
PostPosted: Wed Oct 22, 2008 9:59 am 
Newbie

Joined: Tue Oct 21, 2008 10:31 pm
Posts: 1
I got problem when having two id in one entity.

I have an Order entity. It has one "id" field, which is PK and is generated by Hibernate uuid. It also has a "refNum" field, which is a unique number for other business purpose and is generated by Oracle sequence.

The "id" field is working fine. But, the "refNum" field is always generated a null value and inserting null into table and thus throwing SQL exception: [cannot insert NULL into ("ORDER"."REF_NUM")]

Have I missed something ? Or Have I made any mistakes?

Thanks.

Code:
@Entity
@Table(name="ORDER")
public class Order{

     @Id
     @GeneratedValue(generator = "hibernate-uuid")
     @org.hibernate.annotations.GenericGenerator(
          name = "hibernate-uuid",
          strategy = "uuid"
     )
     @Column(name="ID")
     private String id;


     @Id
     @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="ref_num_seq")
     @SequenceGenerator(name="ref_num_seq", sequenceName="SEQ_ORDER_REF_NUM")
     @Column(name="REF_NUM")
     private Long refNum;


     public Long getId() {
          return id;
     }

     public void setId(Long id) {
          this.id = id;
     }

     public Long getRefNum() {
          return refNum;
     }

     public void setRefNum(Long refNum) {
          this.refNum = refNum
     }
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2008 2:03 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
You can only have one ID attribute. Try making the refNum attribute a regular property and marking it with insert="false" update="false" and generated="insert".

For more info see docs at: http://www.hibernate.org/hib_docs/v3/re ... rated.html and http://www.hibernate.org/hib_docs/annot ... ml#d0e2322


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.