-->
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: one to one mapping: if the releted object is null…
PostPosted: Wed Jul 09, 2008 9:28 pm 
Newbie

Joined: Wed Jul 09, 2008 9:11 pm
Posts: 2
Hibernate version: 1.2.1

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:attempt to delete null

Name and version of the database you are using:sql server 2005

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


I have two class: President, Nation. There are one-to-one relation between them. The Nation is the main class, it has property Persident. The Persident has property Nation, and it's key is generated by the Nation property.

I have a Nation object, and it's Persident is null. When i delete the Nation, it successed, but the delete of Persident is wait to do. So when i access the database next time, it will delete the Persident though the property is null, and throw a exception said: attemped to delete null.

I see the scheam, the one to one relation mapping doesn't has "not-null" attribute as many-to-one relation mapping.

How can deal with this problem?

My mother tongue is not English, I'm sorry.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 10, 2008 2:43 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
A one-to-one association does not support nulls at either end of the association. If a Nation can exist without a President, then you have to use a many-to-one association.

_________________
--Wolfgang


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.