Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cascading deletes

 
Robert Fry
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another numpty question I'm afraid as I get to grips with this technology!

This is concerning two entities - a Floor and a TransmitterLocation. There is a many to one relationship between them so a Floor can hold many TransmitterLocations.
If the floor object is deleted, I want all associated transmitter location objects deleted with it.

Many. many combinations of annotations have been tried, to no effect. The usual thing is nothing ever happens, the transmitter location is undeleted, which causes the app to later fail as it breaks optional constraints.

So, on to the code!



session.delete is being called on a Floor object, and I want all the transmitter locations nukified as well.

The Transmitter class shouldn't actually be involved at all, but I include it anyway as its the only other association the TransmitterLocation class has, so figured I should include my code for that too just in case its some sort of mapping issue of that relationship which is broken. For the sake of completeness and all.

Thanks in advance for any help...
 
Santosh Ramachandrula
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Child element of the parent should be annotated with the cascade option. (I see that in your code you have the getter method annotated. )

JPA syntax::

 
Robert Fry
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Santosh Ramachandrula wrote:Child element of the parent should be annotated with the cascade option. (I see that in your code you have the getter method annotated. )

JPA syntax::



Well, that version is one of the things I tried - ie this



...but that doesn't work either.

By "doesn't work", it does delete the floor object, but not the transmitter location objects - no exceptions or complaints thrown while so doing.

...when you restart the app though it obviously fails on startup due to constraint violations - so the relationship is working and Hibernate can grok that presumably, or the optional = false constraint wouldn't work either.

:?:
 
Robert Fry
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright, I got to the bottom of this, and it wasn't (Java) code related.

Turns out the underlying database had a broken constraint in the TX_PLANPLACE table, and Hibernate was set to not alter the DDL of the underlying DB as it was already in existence before Hibernate was broken out.

Which explains why the annotations were correct but it didn't work anyway.

Buh.


In any case this thread warrants not more headscratching.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic