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