-->
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: Composite Key Auto Generate
PostPosted: Tue Jul 10, 2012 10:56 am 
Newbie

Joined: Mon Oct 25, 2010 11:03 am
Posts: 2
How does Hibernate deal Composite Key to auto generate the a column value. I have My entity as below. In the id variable, I need one of the value to be auto-generated. how do we auto generated key when dealing with composite primary key.

Code:
@Entity
@Table(name="co_dmd_adjt_id "
    ,schema="public"
)
public class CoDmdAdjtId implements java.io.Serializable {


     private CoDmdAdjtId id;
     private Character cdActn;
     private Date effDate;
     private Date expDate;

    @EmbeddedId
    @AttributeOverrides( {
        @AttributeOverride(name="idBsnUn", column=@Column(name="id_bsn_un", nullable=false, length=40) ),
        @AttributeOverride(name="idAdjtFct", column=@Column(name="id_adjt_fct", nullable=false) ) } )
    public CoDmdAdjtId getId() {
        return this.id;
    }

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

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


     private String idBsnUn;
     private Integer idAdjtFct;

    public CoDmdAdjtId() {
    }

    @Column(name="id_bsn_un", nullable=false, length=40)
    public String getIdBsnUn() {
        return this.idBsnUn;
    }
   
    public void setIdBsnUn(String idBsnUn) {
        this.idBsnUn = idBsnUn;
    }

    @Column(name="id_adjt_fct", nullable=false)
    @GeneratedValue(strategy=GenerationType.AUTO)
    public Integer getIdAdjtFct() {
        return this.idAdjtFct;
    }
   
    public void setIdAdjtFct(Integer idAdjtFct) {
        this.idAdjtFct = idAdjtFct;
    }
}


Top
 Profile  
 
 Post subject: Re: Composite Key Auto Generate
PostPosted: Wed Jul 11, 2012 8:09 am 
Newbie

Joined: Wed Jul 11, 2012 3:03 am
Posts: 1
Hibernate supports the automatic generation of some of the identifier properties. Simply use the @GeneratedValue annotation on one or several id properties.

...

You can also generate properties inside an @EmbeddedId class.

_________________
kurt geiger
buy kurt geiger


Top
 Profile  
 
 Post subject: Re: Composite Key Auto Generate
PostPosted: Wed Jul 11, 2012 11:38 am 
Newbie

Joined: Mon Oct 25, 2010 11:03 am
Posts: 2
Kurt,
I did try making one the column my @Embeddable class with @GeneratedValue anototaion but it didn't work. Any help would be appreciated


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.