-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem with Lazy loading one-to-one mappings
PostPosted: Thu Jan 08, 2004 6:37 pm 
Beginner
Beginner

Joined: Thu Sep 04, 2003 1:46 pm
Posts: 20
Hello,

I'm trying to use Lazy Loading on one-to-one mappings.

I followed the delegate pattern.

Here are my mappings:

<class name="com.ditech.loanexceptions.db.LoanDbBean"
table="pub.loans" >
<id name="loanNumber" type="string" column="loan_no" >
<generator class="assigned" />
</id>

...

<one-to-one name="loanException"
class="com.ditech.loanexceptions.db.LoanExceptionsDbBean"
cascade="none"
constrained="true"
outer-join="true" />

</class>

<class name="com.ditech.loanexceptions.db.LoanExceptionsDbBean"
table="loan_except"
proxy="com.ditech.loanexceptions.db.LoanExceptionsDbBean" >
<id name="loanNumber" type="string" column="loan_no" >
<generator class="assigned" />
</id>

...

<one-to-one name="loan"
class="com.ditech.loanexceptions.db.LoanDbBean"
cascade="none" />
</class>

It works except when the LoanException has not been created. I get an ObjectNotFoundException


This, of course, makes sense, but I would like to be able to do logic as follows:

LoanExceptionDbBean exception = loan.getException();

if (exception != null) {
// do logic where exception has been created
} else {
// create the exception
}

I thought I could do this if I simple set the "outer-join" attribute to true.

How can I do this without having to catch the "ObjectNotFoundException"?

Thanks,
-Ben


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2004 6:58 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
constrainted="true" means mandatory association. Mandatory means every LoanDbBean MUST have associated LoanExceptionsDbBean.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2004 7:01 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
Btw, in the case you decide to drop constrainted="true", remember you will lose lazy loading immediately. Lazy loading for 1-to-1 associations is possible for mandatory associations only:

http://www.hibernate.org/117.html#A14

http://www.hibernate.org/162.html


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.