-->
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.  [ 1 post ] 
Author Message
 Post subject: HQL problem in mutli-table request
PostPosted: Wed Jun 06, 2012 6:35 am 
Newbie

Joined: Wed Jun 06, 2012 6:22 am
Posts: 1
Hi everybodey,
I work with Hibernate and Spring in my app, and I don’t succeed to launch a query in 2 different tables.
I have two tables : Goods{goodsId, goodsName, price,…} and GoodsList{glistId, goodsId, slistId, quantity}, où Goods.goodsId = GoodsList.goodsId.
I want to get for each object GoodsId, GoodName, Quantity (you understood that I make a shopping list).
I did the following query : select goods.goodsId, goods.goodsname, goodslist.quantity from Goods as goods, Goodslist as goodslist, where goods.goodsId = goodslist.goodsId

This query return me a List of [Ljava.lang.Object;. If I inspect this list with the debugger, I realize that each object has 3 attributes with the good values needed. But the problem is that these attributs don’t have name, so I cannot access to them !
I tried to give then an alias name in the query (select goods.goodsId as goodsId, goods.goodsname as goodsName,…), but Hibernate return a Syntax error.

I also tried to cast directly the query in an object GoodsCollection created especially for it (composed with 3 attributes named goodsId, goodsName and quantity, a basic contructor which take these three parameters, and appropriates getters and setters). The request is the following :
select new GoodsCollection (goods.goodsId, goods.goodsname, goodslist.quantity) from Goods as goods, Goodslist as goodslist, where goods.goodsId = goodslist.goodsId

But Hibernate return me an error, it said that it cannot find the GoodsCollection class, class that I have imported in the file launching the query.
On the technical part, this query is launch from a file GoodsCollectionDAO created by me, associated with a bean Session Factory in applicationContext.xml, and I use the command getHibernateTemplate().find(queryString);

Thanks to read up to the end, and thank you for your help !


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

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.