[hibernate-issues] [Hibernate-JIRA] Commented: (EJB-272) PostRemove being called before entity is actually deleted

Paul (JIRA) noreply at atlassian.com
Fri Feb 23 13:40:31 EST 2007


    [ http://opensource.atlassian.com/projects/hibernate/browse/EJB-272?page=comments#action_26266 ] 

Paul commented on EJB-272:
--------------------------

I will try to get a test case when I have time, but here are some steps to prove this:

1. Create an entity that has a foreign key association to a parent entity.
2. Don't do any casading with the associations
3. Create a listener on the child entity containing a method annotated with postremove
4. In this method, use JDBC to delete the parent entity by getting the current entity manager, cast it to the hibernate implementation, and get the current connection. 

This will fail because of a constraint violation. This is because the child entity has not been deleted from the database  yet. An easier test might be to try to load the child entity from the database in the postremove method within the same transaction. 

I'm using step 4 in my code. The application that I am working on contains some legacy classes and logic where I can't use casacading to delete the
parent. 



> PostRemove being called before entity is actually deleted
> ---------------------------------------------------------
>
>          Key: EJB-272
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-272
>      Project: Hibernate Entity Manager
>         Type: Bug

>     Versions: 3.2.1
>  Environment: Hibernate 3.2.1GA Entity Manager
> Hibernate core 3.2.2 GA
> Oracle 9i
> Windows XP professional service pack 2
> No application server is being used. 
>     Reporter: Paul

>
>
> I have an EntityListener with a method annotated with postremove.  It seems that the method is being called before the actual entity is deleted from the database. When configuring log4j with "debug" logging it appears that the method is being called after the PreparedStatement is created and configured but before executeUpdate() is called. 
> I see the following statements in my log file before my listener is called
> 14:06:27,024 DEBUG AbstractBatcher:476 - preparing statement
> 14:06:27,024 DEBUG IntegerType:133 - binding '59532' to parameter: 1
> My listener is  called next. Then, the prepared statement is executed. 
> This violates the EJB3 spec. The EJB3 spec states "The PostPersist and PostRemove methods will be invoked after the
> database insert and delete operations respectively."

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list