-->
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: SequenceGenerator issue
PostPosted: Tue May 27, 2008 11:49 pm 
Newbie

Joined: Tue May 27, 2008 11:40 pm
Posts: 2
Hi all,
can we use javax.persistence.SequenceGenerator for the field which is not primarykey field?
I have an entity with two fields of type integer.when i use javax.persistence.SequenceGenerator for primary key field its working fine.But,when i try to use it for other field its not generating any id.
The technologies i am using are

ejb3
hibernate3.1.2
database-postgreSQL

any ideas?
thanks in advance.


Top
 Profile  
 
 Post subject: Re: SequenceGenerator issue
PostPosted: Wed May 28, 2008 1:27 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
I don't believe this will work but you could have your db engine handle this and tell hibernate this field is a generated field. Hibernate then will inquiry the db engine for the right value after an instance is inserted.


Farzad-


Top
 Profile  
 
 Post subject: Re: SequenceGenerator issue
PostPosted: Thu May 29, 2008 12:28 am 
Newbie

Joined: Tue May 27, 2008 11:40 pm
Posts: 2
Thank you for your response.
I think i am not clear in my question so,felt like pasting my code here.
@Entity
@Table(name = "patient")
@SequenceGenerator (
name="PATIENT_ID_SEQ",
sequenceName="patient_id_sequence",
allocationSize=20
)

@Id
@Column(name = "patient_id", nullable=false, length=100)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="PATIENT_ID_SEQ")
public Long getPatientId() {
return patientId;
}

in postgreSQL i defined patient_id column as of type serial and its not a primary key field.
with this code its generating patient ids with sequence like 1,2,3,4..........The problem is
allocation size which i have given is not working.So, i felt the sequence is getting generated by postgreSQL.I dont know what the problem is?How do i make allocation
size working?

any ideas?
thanks in advance.


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.