-->
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: not-null constraint being violated in OneToMany
PostPosted: Fri Dec 11, 2009 4:38 pm 
Newbie

Joined: Fri Dec 11, 2009 4:16 pm
Posts: 3
I have a join table schema relationship represented by OneToMany and ManyToOne associations and am having some trouble getting Hibernate to respect the not-null constraints on the foreign keys.

The schema is similar to the following:
TableA
PKA
<columns A>

Table AB (join table -- two columns as PK)
<PKAB1> (FK to Table A) <-- not-null
<PKAB2> (FK to Table B) <-- not-null
<columns AB>

TableB
PKB
<columns B>


I am using Hibernate Annotations to represent a portion of this as shown below with object A being the owning side of this bi-directional association.

In Object A
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
@JoinColumn(name = "PKAB1", nullable = false)
@IndexColumn(name = "position")
List<AB> getABs()
{
return mTheList;
}

void setABs(List<AB> pTheList)
{
ValidateNoNullElements(pTheList); <-- this is how I know the not-null constraint is not working.
mTheList = pTheList;
}

In Object AB
@ManyToOne
@JoinColumn(name = "PKA", nullable = false, insertable = false, updatable = false)

I read in another post from someone modifying .hbm.xml files directly that the not-null constraint needs to go on the key xml element. I confirmed through hbm2hbmxml that the not-null constraint was not going on the key xml element; though, I have not found a solution through Annotations on how to put it there. The not-null constraint is constantly being placed on the column xml element instead of the key.

Any help would be greatly appreciated!


Top
 Profile  
 
 Post subject: Re: not-null constraint being violated in OneToMany
PostPosted: Fri Dec 11, 2009 8:01 pm 
Newbie

Joined: Fri Dec 11, 2009 4:16 pm
Posts: 3
I suppose a simpler query to the above statement can be made in how can one specify attributes of the key element using annotations?


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.