Sorry about two posts about the same subject. The one you replied did not have all the necessary information. That was a premature "enter key" action.
I understand lists allow duplicates. But the database tables have two unique customers with id 1 and 2.
But the query.find always returns two customers with same id, 2.
thanks
Here is my orinal post.
-----------------------------------------------------------------------------------
[b]Hibernate version: 2.1 [/b]
[b]Mapping documents: [/b]
[b]Code between sessionFactory.openSession() and session.close():
StringBuffer sb = new StringBuffer(200);
sb.append("select cu ");
sb.append("from Customer as cu, CoCustomer as cc ");
sb.append("where cc.coCustomerId = cu.id ");
sb.append(" and cc.customerId = :customerId");
Query query = session.createQuery(sb.toString());
query.setLong("customerId", customerId);
List list = query.list();
[/b]
[b]Full stack trace of any exception that occurs: No Exceptions [/b]
[b]Name and version of the database you are using: MySql - Version 4.1[/b]
[b]The generated SQL (show_sql=true):
select cocustomer0_.id as id__, cocustomer0_.customerId as customerId__, cocustomer0_.id as id0_, cocustomer0_.customerid as customerid0_, cocustomer0_.cocustomerid as cocustom3_0_, cocustomer0_.status as status0_, cocustomer0_.createdon as createdon0_, cocustomer0_.createdby as createdby0_, cocustomer0_.modifiedon as modifiedon0_, cocustomer0_.modifiedby as modifiedby0_ from tbl_cocustomer cocustomer0_ where cocustomer0_.customerId=? order by cocustomer0_.customerId asc
[/b]
[b]Debug level Hibernate log excerpt:[/b]
Above code returns list of customers, but has same customer objects. For example, the query supposed to return two custoemrs with Id 1,2 but always returns two customers with same Id 2.
If run the SQL statement (generated from show_sql=true logs), i am getting two customers with different Ids. So the sql works as expected.
Is there anything wrong with my Customer.equals and hashCode methods or any other pointer to get pass this issue will be appreciated.
We tried without overridding "equals and hashcode" method and also with orverridding, both ways the results are the same.
thanks
-------------------------------------------------------------------------------
|