• 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

Exception on cascade of remove in a unidirectional @OneToMany

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have defined a (MS SQL Server 2008) database for a phone book as following:

Note that the DBA (which is me ) have decided that a subscriber that not have any phone numbers may exist but a phone number must always have a subscriber, that is, the foreign key in PhoneNumber for a subscriber must not be null!

The code in an application that executes this phonebook have this method for remove of a subscriber:

The relation between a subscriber and a phone number is defined as a unidirectional one-to-many relation in subscriber like this

Note that remove of a subscriber should cascade to its phone numbers. When a subscriber is removed should all the phone numbers also be removed.

When the remove is committed in the removeSubscriber method is an exception thrown:

I am currently reading the good book Pro JPA 2: Mastering the Java Persistence API but I have not yet read anything about what the rule is for a situation like that above. To get the application work do I have to make the foreign key subscriber in the PhoneNumber table nullable but I don't know if it is because of a bug in the OpenJPA 2.1 implementation I use or if it is specified to work this way in the JPA 2 specification.

Does anyone know which of those alternatives is true?

In my opinion should I not have to customize the design of the database lika that. Instead should the entity manager in this case with a cascading remove first just remove the phone number and then without any problem remove the subscriber.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic