This content has been marked as final.
Show 4 replies
-
1. Re: Getting generated ID by sequence
rabbiaqaswar Mar 5, 2007 6:03 AM (in response to stupar.aleksandar)try:
@Entity public class Tsperson implements Serializable { @Id @Column(name="TSPERSON_ID", nullable = false) @SequenceGenerator(name = "tsperson_sequence", sequenceName = "SEQ_TSPERSON_ID") @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="tsperson_sequence") private Long tspersonId;
why do you need to flush data? -
2. Re: Getting generated ID by sequence
andydale Mar 5, 2007 1:31 PM (in response to stupar.aleksandar)Hi,
Try declaring your sdequence as so:@SequenceGenerator(name = "tsperson_sequence", allocationSize=1, sequenceName = "SEQ_TSPERSON_ID")
You must have the allocationSize=1 (or some other value) or it uses some kind of hi-lo strategy.
Cheers,
Andy -
3. Re: Getting generated ID by sequence
stupar.aleksandar Mar 12, 2007 3:50 AM (in response to stupar.aleksandar)"andydale" wrote:
Hi,
Try declaring your sdequence as so:@SequenceGenerator(name = "tsperson_sequence", allocationSize=1, sequenceName = "SEQ_TSPERSON_ID")
You must have the allocationSize=1 (or some other value) or it uses some kind of hi-lo strategy.
Cheers,
Andy
When I declare SequenceGenerator with allocationSize
id of object in memory is always id in DB minus one.
Do you know what the problem is, and how can I solve it.
Thnx -
4. Re: Getting generated ID by sequence
rjstanford Sep 13, 2007 2:44 PM (in response to stupar.aleksandar)I'm having a similar problem - using MySQL as the backend (not that I think it matters) and just the default @GeneratedValue option.
I've seen references in other sites that imply that if you use a generated value, the Id will be updated as soon as you call persist(). In our case, before calling persist() it is null (correct), but after calling persist() its always zero.
I've tried doing a refresh() afterwards, but that doesn't seem to make a difference either.
To avoid the questions, we're trying to get the Id of a newly created (and inserted) object so that we can push that Id into Session state. Seems simple enough, right?
-Richard