• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

weird behavior

 
Mohit Sinha
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am experiencing a weird behavior with Hibernate. Let me know your thoughts on this one as I may be missing the details on some behind the scenes Hibernate magic.
I have a table something like this

table test
-----------------------------------------------------
id version samId val1 val2 msg1 msg2, other cols i will skip for brevity

(id,version,samId,val1,val2) are a composite PK.

In one application scenario I get only the id and version. So I have a HQL (tried with Criteria and SQLQuery using Hibernate entity too) something as simple as
------------
select t from test t where t.id=:id and t.version=:version
------------

When i take the Hibernate generated query and fire it in Oracle IDE I get values like
----------------------------------------------------------
1 v1 11 100 500 testMsg1 testMsg2
1 v1 11 501 1000 tmsg1 tmsg2
1 v1 11 1001 2000 tmsg tmsg2
2 v1 12 10 50 testMsg1 testMsg2
2 v1 12 51 100 tmsg1 tmsg2
2 v1 12 101 200 tmsg tmsg2

but when i get the results through Hibernate (i am printing immediately after fetch) they are something like this. The row count is right but the values are messed up
----------------------------------------------------------
1 v1 11 100 500 testMsg1 testMsg2
1 v1 11 100 500 tmsg1 tmsg2
1 v1 11 100 500 tmsg tmsg2
2 v1 12 10 50 testMsg1 testMsg2
2 v1 12 10 50 tmsg1 tmsg2
2 v1 12 10 50 tmsg tmsg2

It just gives me 1 combination. The Hibernate POJO's and xml files for the test table are straight forward as generated by the tool and have not been modified.
The surprising part is the query which Hibernate used under the covers actually yielded a different result when tried in an Oracle editor.

Do let me know if there is something I am doing wrong or look into some setting in the test pojo and xml file.
I have tried this type of query and even complex queries and they have worked very well but this behavior baffled us and the temporary fix we are employing is to use raw sql and fetch the results as object array and create the hibernate pojo object populated out of it.


Let me know your viewpoints on the same.


Thanks,











 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your key definition is probably wrong. It looks like Hibernate can't distinguish between the distinct results. Can you show us how you map your composite key?
 
Pushkar Choudhary
Rancher
Posts: 425
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohit,
Please use a meaningful subject line while posting questions here.
 
Mohit Sinha
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul you are absolutely correct.
Someone had changed the composite keys in the database and hence the confusion.

Many Thanks - Mohit
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic