-->
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.  [ 5 posts ] 
Author Message
 Post subject: AnnotationBinder overrides nullable
PostPosted: Thu Jul 14, 2005 4:30 pm 
Newbie

Joined: Thu Jul 14, 2005 3:24 pm
Posts: 3
Hello,

First of all i'd like to say i'm not any Hibernate guru, so it might be that i'm moaning about the proper behaviour :)

I want to have two one-to-many unidirectional associations, but both mapped to the same join table, for instance:

in one class:

@OneToMany
@JoinTable(
table=@Table(name="TableName"),
joinColumns={ @JoinColumn(name="some_fk", nullable=true)},
inverseJoinColumns={ @JoinColumn(name="some_id") }
)
public Collection<Stuff> getStuff();

and in second:

@OneToMany
@JoinTable(
table=@Table(name="TableName"),
joinColumns={ @JoinColumn(name="other_fk", nullable=true)},
inverseJoinColumns={ @JoinColumn(name="some_id") }
)
public Collection<Stuff> getStuff();

The problem is Hibernate refuses to create columns with nullable set to true, even if i explicitly declare it. I traced through the code a bit and i found the following in org.hibernate.cfg.AnnotationBuilder buildAssociationTableJoinColumns() method:

currentJoinColumn.setNullable(false); //I break the spec, but it's for good

So if i understood this correctly, that "spec violation" is to make sure the column with foreign key is never null, right?
That's probably the proper behaviour for most of the cases, but in above (rare) situation it would be nice to have a few nulls here and there :)

What do you guys think about it? Maybe it should be wise to allow users override the Hibernate's default?

Thanks for the reply.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 14, 2005 5:19 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Do you have a concrete good usage? I don't.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 14, 2005 5:23 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Sorry, I did not read the begining of your post. Forget what I've said.

Do you have to use the same table for your association?
This is incredibly unintuitive, and I think Hibernate core will delete the line when you remove the relationship, so, in your case, it will remove the other one at the same time...

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 15, 2005 2:31 am 
Newbie

Joined: Thu Jul 14, 2005 3:24 pm
Posts: 3
emmanuel wrote:
Do you have to use the same table for your association?


Not really, i'm just exploring Hibernate, thus my stubbornness :) I just wanted to make sure it's not a bug, since the 3.1 version is still under development.

Thanks for your time.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 15, 2005 1:10 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The core of Hibernate has not chagned between H3 and H3.1
We've added significant new features which add some APIs, hence the .1

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.