-->
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: lazy loading on an opposite one-to-one relationship
PostPosted: Fri Feb 27, 2009 10:10 am 
Newbie

Joined: Fri Feb 27, 2009 7:01 am
Posts: 5
Hibernate version: 3.3.1

Hy all

I’m trying to map a one-to-one relationship but I can’t find the right match
I’ve got two objects A and B. B has a foreign key pointing to A.
Here’s a pseudo-code
Code:
class A {
   long id;
   B b;
}
class B {
   long id;
}

But the table structure looks like this
Create table A (
id INT PRIMARY_KEYVAR
)

Create table B (
id INT PRIMARY_KEYVAR,
a_id INT
)

So this would be easy if A had a collection of Bs (using a <bag> and a <one-to-many> tags)
Code:
   <bag name=”bs” >
       <key column=”a_id” />
       <one-to-many class=”B” />
   </bag>

But it’s not a collection.

I could use a <one-to-one> with a <property-ref> if B had a accessors to A such as getA() and setA()
Code:
<one-to-one name=”b” class=”B” property-ref=”a” />
But it doesn’t

The only way I’ve found is by using a <many-to-one> inside a <join> tag
Code:
   <join table="B" >
      <key column="id" />
      <many-to-one name="b" column="a_id" />
   </join>

This however links my two tables threw a join clause and thus can’t perform lazy loading

Is there a way of doing this ?

In short, I need lazy loading on a one-to-one relationship where the accessors are on the opposite side of the relationship to the foreign key?

I hope all this is clear


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2009 10:27 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 8:25 am
Posts: 46
Location: Saint Petersburg, Russian Federation
* "No-proxy" fetching;
* lazy property fetching;


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.