Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.0.2
-
Component/s: None
-
Labels:None
Description
Given a class like:
class UserIdentifier {
static belongsTo = [user:User]
static mapping = {
user lazy:true
}
//...
}
Given a loaded UserIdentifier, I want to be able to get the ID of the "user" without Hibernate doing a select. I do this regularly in pure Java and it is a documented feature in Hibernate (see http://www.hibernate.org/118.html#A21). In Java you can do userIdentifier.getUser().getId() and the full proxy will not be initialized and no select will happen. It makes sense because the User ID is in the UserIdentifier table due to the belongsTo. In Grails, as soon as you do a userIdentifier.getUser() it does a select of the associated user.
The nature of the groovy runtime is that is triggers the initialization of the object when the metaclass is accessed for some reason. I'm not sure if this is fixable from a Groovy perspective. What I have done though is add a new meta-property that by convention ends in "Id" so you can do
And it won't initialise the lazy proxy