Cascading delete has problem removing entity after its dependent is removed
---------------------------------------------------------------------------
Key: EJB-396
URL:
http://opensource.atlassian.com/projects/hibernate/browse/EJB-396
Project: Hibernate Entity Manager
Issue Type: Bug
Components: EntityManager
Affects Versions: 3.4.0.GA
Reporter: Wade Routen
Attachments: hibernatebug.zip
Hello Hibernate people,
I searched through your forums trying to find any mention of the problem I have ran into
and normally I would post this to your forums to see if anyone would give me a response
but I'm new to the forums and didn't see a spot to attach code other than inline
on my message, however, this takes a bit more than can be posted inline. I have attached
the code to reproduce the issue I'm seeing and it is a quite strange one at that.
Here's the problem:
In the code there are 3 entities set up; Directory, Person, and Blacklisted. Directory has
a "one to many" relationship on both Person and Blacklisted. Person has a
"many to one" on Directory, and Blacklisted has a "many to one" on
Directory and Person. When the cascade for the delete occurs for directory, given the way
the Directory is currently setup in the example code, the Person relationship is
evaluated and deleted first for the cascade and is deleted successfully. Next the
Blacklisted relationship is evaluated which is where the problem comes into play. The
Person entity is marked as "DELETED" and there for is marked as NULL within the
Blacklisted "DeletedState" via this method call
(Line: 270 of DefaultDeleteEventListener) new ForeignKeys.Nullifier( entity, true, false,
session ).nullifyTransientReferences( entityEntry.getDeletedState(), propTypes );
When the next line executes the Nullability check, the "Person" reference (which
is not null in the entity) is checked for Nullability, the deletion fails out claiming
that the entity is null and can not be due to the fact that is was nulled out in the
entity's DeletedState. The thing is that this only happens when the Directory
entity's column field references are arranged a certain way. It's hard to explain
but the code will show you that if the "people" field is alphabetically before
the Blacklisted field, currently named "suspended" in the example code, this
problem occurs. If you were to rename the "suspended" field to
"blacklisted", or anything alphabetically before "people", the problem
does not occur and the cascading delete goes through without a hitch. Now obviously
Hibernate processes fields on the cascade in alphabetical order, and if not maybe the
Nullifier shouldn't be nulling out the entity for cascade in the Delete State. At any
rate I suppose that's for you guys to figure out. I hope this is helpful...
Regards,
Wade Routen
--
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira