-->
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.  [ 3 posts ] 
Author Message
 Post subject: Help, Hibernate's returning the wrong object
PostPosted: Fri Sep 17, 2010 3:43 pm 
Newbie

Joined: Thu Nov 19, 2009 6:13 am
Posts: 3
Hi guys,

I have a query that looks like this

Code:
Document document = DocDAO.getSession().read(someId);
MyFile file = (MyFile) DAO.getSession()
.createQuery("SELECT file FROM MyFile file WHERE file.document = :document AND file.version = :version")
.setParameter("document", document)
.setParameter("version", version)
.uniqueResult();

Now, I should get a file where file.getDocument().getId() == someId, and someId is a BigInteger (in MySQL, a bigint(20). But unfortunately, they are not equal. What kind of errors can lead to the queried entity not being the entity I was looking for?

Cheers

Nik


Top
 Profile  
 
 Post subject: Re: Help, Hibernate's returning the wrong object
PostPosted: Fri Sep 17, 2010 5:10 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
file.getDocument().getId() == someId, and someId is a BigInteger


Don't compare objects using ==. Use equals() instead.


Top
 Profile  
 
 Post subject: Re: Help, Hibernate's returning the wrong object
PostPosted: Fri Sep 17, 2010 7:13 pm 
Newbie

Joined: Thu Nov 19, 2009 6:13 am
Posts: 3
nordborg wrote:
Don't compare objects using ==. Use equals() instead.


My bad, what I meant to say is that both Ids should have the same values, but they don't. Instead I get another instance of the same class


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

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.