Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Cannot Reproduce
-
Affects Version/s: None
-
Fix Version/s: None
-
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.
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
This seems to return null in the case where the base object is not yet saved, but associations are set.
I've tried step debugging through this issue and I'm seeing that a NoSuchMethodException is being thrown in
GrailsDomainConfigurationUtil.getAssociationIdentifier
I'm thinking this could be caused by the use of the constructor over a hibernate proxy as loaded from a Feedback.get(id) call.
At any rate, I've had to use the second form for now (feedback.from.id), although in this case I could have got a way with just using the parameter.