i really can not find enough documentation on hibernate IN keyword, when applied on search within a collection of some object. I have strange problem, I have a hql query:
FROM Contact co, IN (co.categories)categories WHERE categories.name = ?
In i was expecting list of Contacts ofcourse. But something is wrong with it, because it is not returning list of Contact objects, but list of Object[]????? Is it syntax or this is totally wrong??
Here are mapping parts:
<set lazy="false" name="categories" table="ContactCategory">
<key column="id" foreign-key="fk_contact_category" />
<many-to-many class="Category" column="catid"
foreign-key="fk_contact_category2" />
</set>
<class name="Category">
<id column="catid" name="Id" type="long">
<generator class="sequence" />
</id>
<property length="50" name="name" type="string" />
</class>
Important thing to mention: This query is made with the query builder. This is printout of one of generated queries where its failing. Very weird is that – i am getting the correct number of objects in this list, I check the database and number is correct with given parameters, but I dont get Contact objects, but some Object arrays in the List.
Appreciate all the help
You need to add
SELECT coso that your Query is
SELECT co FROM Contact co, IN (co.categories)categories WHERE categories.name = ?The
SELECT cois necessary, to tell Hibernate which one item it should return per result set line.SELECT co FROM Contact co LEFT JOIN co.categories cat WHERE cat.name = ?I have seen the
INkeyword only in the Where – clause so far. In Stuff like this,FROM catagories cat WHERE cat.name IN ('HALLO', 'WORLD')