[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Re: Getting generated ID by sequence
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 View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4084153#4084153 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4084153 ___ jboss-user mailing list jboss-user@lists.jboss.org https://lists.jboss.org/mailman/listinfo/jboss-user
[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Re: Getting generated ID by sequence
"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 View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4027067#4027067 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4027067 ___ jboss-user mailing list jboss-user@lists.jboss.org https://lists.jboss.org/mailman/listinfo/jboss-user
[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Re: Getting generated ID by sequence
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 View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4025152#4025152 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4025152 ___ jboss-user mailing list jboss-user@lists.jboss.org https://lists.jboss.org/mailman/listinfo/jboss-user
[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Re: Getting generated ID by sequence
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? View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4025013#4025013 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4025013 ___ jboss-user mailing list jboss-user@lists.jboss.org https://lists.jboss.org/mailman/listinfo/jboss-user