I have this physical schema (don't blame me, it's not my design):
Code:
table cl_address (Address):
----------------
n_key_address [PK]
n_key_entity [FK to cl_entity, but is null if n_key_person is not null]
n_key_person [FK to cl_person, but is null if n_key_entity is not null]
table cl_entity (Entity):
----------------
n_key_entity [PK]
table cl_person (Person):
----------------
n_key_person [PK]
There are other tables which will point to Address, in which case
both of the FKs on cl_address will be null.
I want to model this as a kind of parent/child associaton. I want both Entity and Person to have collections (Sets) of Address objects.
But I have no real desire for there to be back-pointers from Addres to Entity/Person.
So, I've mapped the Address object itself without Entity or Person attributes, and mapped a collection of Addresses on Entity and Person as one-to-many, cascade=all, inverse=
false. Lets say I don't mind the redundant insert-then-update behaviour (I do mind it, but I can live with it).
Problem is, we like to specify "no default" on our column definitions, but since the Address class has no attributes to point to Entity/Person, Hibernate doesn't know about these two columns, so it can't include them in the insert statement, which then causes the SQL to barf.
Once I put "with default null" on the n_key_entity and n_key_person columns in cl_address everything works fine.
Is there any way to tell hibernate about the columns for the purposes of the insert statement? Using the insert attribute on a property definition, I can tell Hibernate *not* to use a column in an insert - but is there anyway to tell hibernate "just for inserts, make sure you insert this column with null in it"?