-->
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.  [ 4 posts ] 
Author Message
 Post subject: ManyToOne(optional=false) with @Column(nullable=true)
PostPosted: Wed Jul 09, 2008 9:28 am 
Newbie

Joined: Mon Nov 14, 2005 5:17 am
Posts: 13
Hey,


I have few entities inherited from a parent entity which is annotated with:
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)

The subclasses entities has few ManyToOne relationships with other entities,


Since all the columns are kept in a SINGLE TABLE all the foreign keys columns must be nullable, (otherwise I get SQL exceptions when saving one of the entities due to missing values of the other foreign keys related to other entities),


So I tried to do in the child entities something like:

@ManyToOne(optional=false)
@JoinColumn(name="FOREIGN_KEY_ID", nullable=true)



I was sure that nullable=true means that the column will be created as nullable in the DB schema while 'optional=false' will make sure that the relationship was set by hibernate,



In reality, the column is created as NOT NULL (although I set nullable=true)


Is it the expected behavior? and if so, how can I make sure that when working with one of the child entities the relevant foreign entities are set?




Many thanks,


Asaf.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 09, 2008 10:14 am 
Regular
Regular

Joined: Tue Jun 03, 2008 1:12 pm
Posts: 84
Location: germany
Try it with

@NotNull

instead of nullable=true


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 10, 2008 9:45 am 
Newbie

Joined: Mon Nov 14, 2005 5:17 am
Posts: 13
Hey,

Can you explain?

I mean, I know @NotNull is a hibernate validator but what about the @Column(nullable=X)/@ManyToOne(optional=X) options?


Are they documented somewhere? and what is the expected reaction when using them both together/separately?



Many thanks,


Asaf.


Top
 Profile  
 
 Post subject: Re: ManyToOne(optional=false) with @Column(nullable=true)
PostPosted: Sat May 18, 2013 3:12 pm 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
I created a JIRA for this https://hibernate.atlassian.net/browse/HHH-8229


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.