-->
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.  [ 1 post ] 
Author Message
 Post subject: Getting id from lazy loaded object without query
PostPosted: Sun Nov 27, 2011 7:00 am 
Beginner
Beginner

Joined: Sun Apr 25, 2010 7:14 am
Posts: 30
Hi,

i have the problem that every time i access the id field from a lazy loaded object (@ManyToOne) the whole object is loaded by a select althought this
should not be needed as the id is already loaded with the main object. I found out that hibernate usually doesn't do this when using
property level annotations. As i would like to use field annotations i searched for a solution for this way and found the @AccessType
annotation.
http://256.com/gray/docs/misc/hibernate ... ions.shtml

This seems to work:
Code:
@Id
@AccessType("property")
private Long pktable;

public Long getPktable() {
  return this.pktable;
}

The problem is that i have a second getter for the id (inherited general method for all beans) and everytime i access the id using
this second method hibernate still loads the whole object:
Code:
@Id
@AccessType("property")
private Long pktable;

// works
public Long getPktable() {
  return this.pktable;
}

// loads whole object
public Long getId() {
  return this.pktable;
}

Is there a way to tell hibernate that this getter also just retrieves the id and a load is not needed?

Thanks a lot!

Yours
Thomas


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.