-->
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: composite element and nullable properties
PostPosted: Wed Jul 07, 2004 7:58 am 
Newbie

Joined: Mon Dec 29, 2003 11:30 am
Posts: 3
I have a rather simple question. I was reading through the hibernate tips and tricks faq and came to the following question.

I have a many-to-many association between two tables, but the association table has some extra columns (apart from the foreign keys). What kind of mapping should I use?
Use a composite-element to model the association table. For example, given the following association table:

create table relationship (
fk_of_foo bigint not null,
fk_of_bar bigint not null,
multiplicity smallint,
created date )

you could use this collection mapping (inside the mapping for class Foo)

<set name="relationship">
<key column="fk_of_foo"/>
<composite-element class="Relationship">
<property name="multiplicity" type="short"/>
<property name="created" type="date"/>
<many-to-one name="bar" class="Bar"/>
</composite-element>
</set>


I also noticed the following in the hibernate manual: "Please note that a composite element mapping doesn't support null-able properties if you're using a <set>."

So my question is, in the above mapping from the faq, are the properties 'multiplicity' and 'created' allowed to be null? More precisely put, is the mapping from the faq correct since the ddl for the table will allow null values?

Thanks,
Mike


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 07, 2004 8:06 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
The FAQ mapping was wrong, I fixed it. If you need nullable columns, use an <idbag> with a <composite-element>.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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.