[jboss-jira] [JBoss JIRA] Commented: (EJBTHREE-553) PrePersist callback method not called if entity's primery key is null
Mark Menard (JIRA)
jira-events at jboss.com
Thu Sep 21 19:15:07 EDT 2006
[ http://jira.jboss.com/jira/browse/EJBTHREE-553?page=comments#action_12343792 ]
Mark Menard commented on EJBTHREE-553:
--------------------------------------
I'm also having this issue, setting my id in the @PrePersist method, and I'm going to apply Michal's patch to Hibernate to work around it.
I would like to ask though is this the way it is supposed to work? Or should we just not generate ids in the @PrePersist method?
> PrePersist callback method not called if entity's primery key is null
> ---------------------------------------------------------------------
>
> Key: EJBTHREE-553
> URL: http://jira.jboss.com/jira/browse/EJBTHREE-553
> Project: EJB 3.0
> Issue Type: Bug
> Environment: jboss-4.0.4.CR2
> Reporter: Michal Borowiecki
>
> When an entity is persisted which does not have its primary key set (and it is not annotated with GeneratedValue annotation), the @PrePersist callback method is not invoked.
> Instead the exception is thrown:
> Caused by: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): com.bluemedia.system.User
> at org.hibernate.id.Assigned.generate(Assigned.java:33)
> at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:98)
> at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
> at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
> at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
> at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:617)
> at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:591)
> at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:595)
> at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:187)
> ... 64 more
> This is in conflict with ejb 3.0-pfd spec, which states (sec. 3.4.2) :
> "The PrePersist and PreRemove callback methods are invoked for a given entity before the respective EntityManager persist and remove operations for that entity are executed."
> Since the spec states that EntityManager's persist operation is executed after the PrePersist callback methods, setting the value of the primary key in a PrePersist callback method seems a reasonable use case.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list