[
http://jira.jboss.com/jira/browse/EJBTHREE-553?page=all ]
Carlo de Wolf closed EJBTHREE-553.
----------------------------------
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: AS 5.0.0.Beta3
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