I seem to be having some difficulty with a query in hibernate. I am performing an inner join on two tables.
SELECT * FROM product p INNER JOIN warehouse w ON p.wid = w.id
Product Table:
id | name | wid | price | stock .....
Warehouse Table:
id | name | city | lat | long .....
The join result:
id | name | wid | price | stock | id | name | city | lat | long .....
When I run the query..
Session.createSQLQuery(this.query)
.addEntity("p", Product.class)
.addEntity("w", Warehouse.class).list();
So for every result I get an object containing a Product object
and a Warehouse object
.
This is expected. The issue is hibernate assigns the id and name of the product to the warehouse objects id and name property. Its as if the first two columns in the join result are over riding when it comes to creating the Warehouse project. The Product object always contains the correct data.
Any suggestion on finding a way around this issue so the id and name columns representing the correct Warehouse data would be much appreciated.
Thanks in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…