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 !
|