|
ebj3 event listeners currently perform lifecycle callbacks in the overriden invokeSaveLifecycle method, which is only invoked after validation has succeeded. I moved the callback invocation before validation by overriding the saveWithGeneratedId method. This seems to have fixed the issue. I attach the patch. From what I could determine: I've also modified EJB3SaveEventListener and EJB3SaveOrUpdateEventListener although I couldn't find the circumstances when they're used. However, since they all subclass AbstractSaveEventListener I figured it is better to modify them accordingly. As for the PreUpdate callback I think it is called before validation, as it should be. The PreUpdate bug I referred to earlier is now This is an updated version of Michal's patch. This is done against hibernate-eventmanager-3.2.2.CR2. Correction to my note on the patch. This is done against hibernate-eventmanager-3.2.0.CR2. Hi, Hi Emmanuel, This patch fixes the following scenario. Create an entity with new (). Do not set the primary key. Call EntityManager.persist() on the new entity with a null primary key. The entity has a method marked with @PrePersist to set the primary key on the entity, but Hibernate checks the primary key before executing the @PrePersist method. Thus it throws an exception like the following: Caused by: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): If you could give me pointers on how to create a test scenario that would illustrate this I'd be happy to try, but I'll admit I'm a complete Hibernate novice. The only experience I have with Hibernate was downloading Michal's patch, and applying it by hand to 3.2.0.RC2, building, and using the jars thus created. This issue (I think) is also affecting Id Classes. I have an Invoice class which contains a one to many relationship with InvoiceLine, InvoiceLine has a composite key made up of the Invoice Id (sequence generated) and the InvoiceLine Id. I'm using the @IdClass annotation and NOT embedded ids. I'm trying to use @PostPersist on the Invoice object to update the InvoiceLines with the sequence generated Invoice id. However, it appears that Hibernate is creating the IdClass instance before I've had a chance to update the fields on InvoiceLine: [DEBUG] AbstractSaveEventListener - generated identifier: component[invoiceId,invoiceLineId]{invoiceLineId=1, invoiceId=null}, using strategy: org.hibernate.id.Assigned Therefore my @PostPersist method in Invoice has no affect because I can't change the value of invoiceId on the IdClass, only on the InvoiceLine. If you think this is a separate issue let me know and I'll open another bug. Rename case, since the initial description has been fixed a long time ago and the discussion have slipped. Note that I still consider such a usage hacky and is not considered a supported behavior (mainly becasue it highly depend on the Hibernate state discovery mechanism). |
|||||||||||||||||||||||||||||||||||||||||||||||||
Hi,
This is also a problem with with my current project. And is also located at
http://jira.jboss.com/jira/browse/EJBTHREE-553
Anybody know of any fixes or workarounds.
Thanks
Grant