I am using JBOSS 4.2 with a MySql database. I am running a native query through the entity manager (the query is messy but I will post if anybody wants to see all of it). Running the query through the MySQL query browser produces the expected results. However, when running it with the entity manager, adding a field into the select clause changes the result. For example,
SELECT loan.id, account1.balance
// rest of nasty query
177 456.229 (correct result)
Select loan.id, account2.balance, account1.balance
loan.id account2.balance account1.balance
177 123.44 123.44 (correct result for account 2, but not for account 1)
The queries don't differ in anything except the select statement, and it seems that the wrong values are somehow being overwritten. Has anybody seen something like this before or can you offer some suggestions? Thanks for your help.
I've figured out that I probably need to define a SQLResultSetMapping. If that's the case, my question is whether I can have such a mapping for a query that returns multiple instances of the same entity (like the accounts in the original post).