Alright, that was definitely a nudge in the right direction. Now i need to figure out specifically how to extract (via runtime meta data) what a collection of entities is 'mappedBy' - that is, say I have a Foo and Foo has a collection of Bars. The collection of Bars are mappedBy 'foo'. I know thus, hat by iterating over each item in that collection and setting whatever property is used in mappedBy to null and also removing the object from the collection, that I will not have any foreign key constraints on that Foo.
The code to handle any one of these sorts of situations looks roughly like:
Code:
Foo f = ... ;
Collection<Bar> bars=f.getBars() ;
Collection<Bar> toRemove=new ArrayList<Bar>();
for(Bar b : bars) {
toRemove.add(b) ;
b.setFoo( null) ;
}
for(Bar remove : toRemove)
f.getBars().remove(remove) ;
Its boilerplate, and it needs to be done each time i want to unentangle an object so I can delete it. If we add another association with the modeling tool and it touches Foo, then we need to modify the appropriate deletion method because itll now blow chunks. I want to build a smarter mouse trap. In this case, the collection of Bars were mapped by foo. Setting bar.foo = null and then removing bar from foo's collection of bars works.
I appreciate your prompt reply, and thanks in advance for any further insight. Essentially, I want to do the above, but via reflection and via the runtime data available through Hibernate's APIs. In my case, all associations ae bidirectional, and all associations are one to many or one to one, so the above ought to work (or I just null out each objects pointer to the other for the one to one case).
Thanks again.