[jboss-user] [EJB 3.0] - Generate ID when creating entities

hamtho2 do-not-reply at jboss.com
Tue Jan 29 04:12:40 EST 2008


is there a chance to let the EntityManager create the ID at creation-time of an entity?

I´ve got the problem, that I want to share one id between multiple entities while having a unidirectional one-to-one relation.
This way I only have a generated value at the parent-object and for the dependent entities I have to set the id manually (to the same id, as the parent). Unfortunately the id is only generated when persisting the entity (before that the value is null), so it´s hard to propagate an object-reference to the dependant entities (even with @PrePersist as I would have to parse the parent-object). 
So what I could do is to manually get the next value from my sequence and set this as an id for every entity. But if the id would be generated when a new entity is created, there won´t be a problem at all. Is there a way to achive this? 

Any input would be greatly appriciated.


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4124303#4124303

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4124303

More information about the jboss-user mailing list