-->
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.  [ 1 post ] 
Author Message
 Post subject: Can one of EmbeddedId columns be generated by sequence?
PostPosted: Thu Jan 26, 2012 11:42 am 
Beginner
Beginner

Joined: Wed Sep 06, 2006 12:08 pm
Posts: 48
Location: Warsaw - Poland - Europe - Milky Way
Hi All

I've got a two-column primary key mapped like this:

Code:
   @Embeddable
   public static class BSCSFeesPk implements Serializable
   {
      private long  customerId;
      private long  seqNo;
      [...]



This is primary key of my entity BSCSFees:

Code:
@Entity
@Table(name="FEES")
@org.hibernate.annotations.Entity(dynamicUpdate=true, dynamicInsert=true)
public class BSCSFees
{
   private BSCSFeesPk     pk;

   @EmbeddedId
   public BSCSFeesPk getPk()
   {
      return pk;
   }

    [...]


During persisting of the entity I know the first value: customerId
Second value of primary key (seqNo) I'm generating manually hitting database sequence.

Is it possible in Hibernate to generate this sequence value automatically by Hibernate?
I would be glad to use something like this (but this code doesn't work :( ):

Code:
      @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="feesSeqnoGenerator")
      @SequenceGenerator(name="feesSeqnoGenerator", sequenceName="MAX_FEES_SEQ", allocationSize=1)
      @Column(name="SEQNO", nullable=false, precision=18, scale=0)
      public long getSeqNo()
      {
         return seqNo;
      }



Any ideas?

Take care,
Adam


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

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.