Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Associating object with static lookup tables

 
Doug MacKenzie
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use the cascade attribute in your association mapping (or use cascade=none).
 
Doug MacKenzie
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still can't get this to work. Any other suggestions?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic