[jboss-jira] [JBoss JIRA] Resolved: (EJBTHREE-553) PrePersist callback method not called if entity's primery key is null

Emmanuel Bernard (JIRA) jira-events at lists.jboss.org
Wed Feb 14 14:50:31 EST 2007


     [ http://jira.jboss.com/jira/browse/EJBTHREE-553?page=all ]

Emmanuel Bernard resolved EJBTHREE-553.
---------------------------------------

    Fix Version/s: EJB 3.0 RC11 - FD
       Resolution: Done
         Assignee: Emmanuel Bernard

http://opensource.atlassian.com/projects/hibernate/browse/EJB-46
Fixed in HEM 3.2.2

> 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
>         Assigned To: Emmanuel Bernard
>             Fix For: EJB 3.0 RC11 - FD
>
>         Attachments: EJB3EventListener_v2.patch
>
>
> 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