Thread:
 Association: Person [1 <--> 0..1] Note does not wo... 
 pearl8   17 Sep 2006, 01:43 

Comment
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
From: pearl8 (17 Sep 2006, 01:43) Replies: 0, Views: 26967
Subject: Association: Person [1 <--> 0..1] Note does not work
My 0.02รง

The eg. by Regis Pires Magalhaes

Association: Person [1 <--> 0..1] Note

is not really a [1 <--> 0..1] but more of a 1 <----> 1

I find that for a Person if you DO NOT create a note, the save goes 
through fine, but when you try to Load the Person.getNote() then:

1. a proxy is created
2. person.getNote() evaluates to not null even if there are no notes for 
a person
3. person.getNote().getNoteDetails() or some such method bombs with an 
Exception:org.hibernate.ObjectNotFoundException: No row with the given 
identifier exists

In my experiments, rather, if this is modeled as a many-to-one from 
Person to Note with a NOTE_ID being stored in the Person Table, then 
that approach is much more conducive to a unidirectional Person [1 <--> 
0..1] Note

Something like this in Person:

        <many-to-one name="note" class="Note" column="NOTE_ID" 
unique="true" cascade="all"/>   

With this in Note:

  <class name="Note" table="NOTE">

	<id name="id" column="NOTE_ID" type="long">
	 <generator class="increment"></generator>
	</id>
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
© Copyright 2006, Red Hat Middleware, LLC. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc. [Privacy Policy]