• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cascading deletes

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic