GeeCON Prague 2014*
The moose likes Object Relational Mapping and the fly likes Associating object with static lookup tables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Associating object with static lookup tables" Watch "Associating object with static lookup tables" New topic
Author

Associating object with static lookup tables

Doug MacKenzie
Greenhorn

Joined: Feb 18, 2009
Posts: 13
Ok, this is probably going to make people ask why the database is setup this way. To make a long story short, I don't have control of the database schema

I have two objects
objA and objB

objA will contain user input, one of which will be a selected instance of objB

Instances of objB are loaded during application startup and displayed to the user for them to select

An instance of objA will\must contain at least one instance of objB

So I have two tables
A and B

A will contain the user input and will refer to a row of B
B contains lookup values that I can not delete

A and B are joined via A_B

Now I've managed to create a mapping that allows me to insert objA into table A, and A_B will contain a references to rows in B. However, when I delete objA it's trying to delete rows from B as well. Unfortunately this will never work since B is used by many tables, and even if it wasn't it's a lookup value that I don't ever want removed. So the constraint violations I'm getting are to be expected. What I need to do is delete from A and from A_B but not from B.

Just to complicate matters objC will contain a set of objA
Here's my current mapping


Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Don't use the cascade attribute in your association mapping (or use cascade=none).


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Doug MacKenzie
Greenhorn

Joined: Feb 18, 2009
Posts: 13
If I don't use the cascade attribute, or set it to none, it doesn't save any values in the join table A_B
Doug MacKenzie
Greenhorn

Joined: Feb 18, 2009
Posts: 13
Still can't get this to work. Any other suggestions?
 
GeeCON Prague 2014
 
subject: Associating object with static lookup tables