Using Hibernate 2.1.7...
I'm porting a legacy persistence framework to hibernate. We have a lot entities with natural keys and to-one relationships to these tables from other entities. If I want to create an many-to-one association to this table and also be able to access the foreign key value without fetching the related entity, the only resolution I can find is to have one of the two mapped as insert=false update=false. I currently have the association mapped as insert=false, update=false, which seems to work better than doing it vice-versa.
The problem is that it's causing me a great deal of grief trying to manage two different ways to set what amounts to the same value. For example, if they call setFoo( Foo value ) and then call getFooId(), the getFooId() method will return an old value or null unless the setFoo() method is written to keep the other value in synch.
FYI, we are using hbm2java to generate the code, but I have a custom renderer to try and fixup some of these issues. However, generating code to keep the foreign key value in synch when they set the association property seems tedious and messy.
Am I totally off-base here with what I want to do? Anyone else with a similar situation?
~Aaron
|