-->
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: @Formula field values not valid when getter called
PostPosted: Thu Sep 13, 2012 9:37 am 
Newbie

Joined: Thu Sep 13, 2012 9:33 am
Posts: 1
I have the following annotation in an Entity - in this case I'm just creating a formula to grab the user id for simplicity - it is the same value mapped earlier with @Id
Code:
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "USER_ID", nullable = false)
private long userId;
...
@org.hibernate.annotations.Formula("USER_ID")
private int testme;


Now when I do a query:
Code:
User user2 = (User) em .createQuery("select u from User u where u.userId = ?1")
       .setParameter(1, user.getUserId()).getSingleResult();

and do a get on the formula field:
Code:
System.out.println("test field: " + user2.getTestme());

I get 0 (zero). In the logs I see the correct SQL mapping to a formula column in the projected fields. For some reason, it is not populating the class attribute (field) with the computed value. Indeed the only way to get the correct value (1) is to put it explicitly in the projection:
select u.testme from .... <--- this works I think I should be able to get to derived fields via their getters and expect the value to be present

Are formula fields supposed to be populated and the getter able to access the value upon successful query?

Versions:
annotations 4.0.1, core, entitymanager 4.1.3, validator 4.2.0


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.