-->
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: Simple lazy association not working?
PostPosted: Wed Nov 28, 2007 11:06 am 
Newbie

Joined: Wed Nov 28, 2007 10:53 am
Posts: 1
Hi, I'm set up a simple one-to-one association (using Hibernate-3.3.0GA) between to classes (using annotations) and I'm trying to specify lazy loading, however I see selects for the second table in my log output. Here's what I've got:

@Entity
@Table(name = "members")
class Member {
...
private Contact contact;
...

@Id
@Column(name = "member_id")
public long getId() {
return id;
}
...
@OneToOne(fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn
public Contact getContact() {
return contact;
}
}

@Entity
@Table(name = "contactinfo")
public class Contact {
...
@Id
@Column(name = "contactinfo_id")
public long getId() {
return id;
}
...
}

My test method accesses the Member object like this:

...
session.beginTransaction();
Member m = null;
m = (Member)session.load(Member.class, id);
session.getTransaction().commit();
...

When I run this, I see selects for 'members' as well as 'contactinfo' tables in my log output.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 28, 2007 5:17 pm 
Newbie

Joined: Sat Dec 25, 2004 11:18 pm
Posts: 11
Hey

Change OneToOne(fetch = FetchType.LAZY) to OneToOne(fetch = FetchType.LAZY,optional=false)

I hope it should work!

Regards

Manan


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 13, 2008 3:26 pm 
Newbie

Joined: Sun Jan 13, 2008 3:16 pm
Posts: 5
Location: New Zealand
Hi Mananmehra

I had this problem as well and this change made lazy fetching work thanks. Were wondering though what happend when you want optional=true and want lazy loading because this always loads eager even if it has been definded lazy ???

regards Dave

_________________
Hibernate newbie


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.