-->
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: [help] How to define a "not-null" one-to-many rela
PostPosted: Sun Feb 17, 2008 6:38 pm 
Newbie

Joined: Sun Feb 17, 2008 6:26 pm
Posts: 3
Hi, there,

I'm a newbie of Hibernate, could you please give me some help over this problem?
I can't put too many words in the title so many it's not well explained...

My question is: I have to define an association like shown below:

| A |----------------- | B |
........(1..*)..........(1)

So I defined at the A side a "many-to-one" with not-null="true", and at the B side a "one-to-many" association:

<set name="myA" inverse="true">
<key column="B_ID"/>
<one-to-many class="A"/>
</set>

I tried to put a not-null="true" there too:
<one-to-many not-null="true" class="A"/>

but it's not allowed.

I spent quite some time searching for a solution but got nothing... Anyone could give me a hand?

Thanks a lot.


Top
 Profile  
 
 Post subject: Re: [help] How to define a "not-null" one-to-many
PostPosted: Sun Feb 17, 2008 6:51 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
It doesn't make sense to put a not null on one-to-many since the one-to-many side is not usually the owner of the relation so if you only put it on the many-to-one side it is good enough.



Farzad-


Top
 Profile  
 
 Post subject: Re: [help] How to define a "not-null" one-to-many
PostPosted: Mon Feb 18, 2008 4:30 am 
Newbie

Joined: Sun Feb 17, 2008 6:26 pm
Posts: 3
farzad wrote:
It doesn't make sense to put a not null on one-to-many since the one-to-many side is not usually the owner of the relation so if you only put it on the many-to-one side it is good enough.



Farzad-


Thanks Farzad. I got it.
But how can I then guarantee the "many" side to be "not null"?


Top
 Profile  
 
 Post subject: Re: [help] How to define a "not-null" one-to-many
PostPosted: Mon Feb 18, 2008 11:14 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
starlighting wrote:
Thanks Farzad. I got it.
But how can I then guarantee the "many" side to be "not null"?


I am wondering if you could use hibernate validation extension. It gives you enough facilities to make sure a collection has a minimum size.


Farzad-


Top
 Profile  
 
 Post subject: Re: [help] How to define a "not-null" one-to-many
PostPosted: Mon Feb 18, 2008 6:24 pm 
Newbie

Joined: Sun Feb 17, 2008 6:26 pm
Posts: 3
farzad wrote:
starlighting wrote:
Thanks Farzad. I got it.
But how can I then guarantee the "many" side to be "not null"?


I am wondering if you could use hibernate validation extension. It gives you enough facilities to make sure a collection has a minimum size.


Farzad-


Great!! Thanks a lot, I'll try it right now, :)


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.