-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Tellin Hibernate about unmapped properties for the insert?
PostPosted: Thu Dec 11, 2003 1:07 am 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
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"?

_________________
Cheers,
Shorn.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 3:15 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
every database I know of automatically inserts null if the column does not appear in the INSERT SQL.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.