Isn't there a way with Hibernate to return a list of (primitive) values from one column in a table? I need this for a subselect where I only want rows where a particular field is not in a list of ids from another table.
A:
Can you use a Hibernate raw SQLQuery?
SQLQuery q = getSession().createSQLQuery("select int_column from table");
List<Integer> list = (List<Integer>) q.list();
Kevin
2009-05-18 18:11:48
A:
Dont know about using the hibernate engine itself, I think this will depend on how youve mapped your model objects, short of seeing the mappings, you can go via the hibernate session object and use standard SQL;
session.createSQLQuery("select idCol from someTable where someId not in (
select someId from anotherTable)");
Then use the list() method on the query, and use autoboxing for the primtive int array.
simon622
2009-05-18 18:12:16
+2
A:
well it turned to be as simple as something such as the following, from the URL https://www.hibernate.org/hib_docs/nhibernate/html/queryhql.html which was actually one of the first results I found when googling but I was concerned it might be NHibernate specific
from Eg.DomesticCat as cat where cat.Name not in (
select name.NickName from Eg.Name as name )
George Jempty
2009-05-18 18:15:56
FYI, the link you posted is to the NHibernate documentation. The equivalent documentation for the Java version of Hibernate is here: http://docs.jboss.org/hibernate/stable/core/reference/en/html/queryhql.html
Paul Morie
2009-05-18 19:54:36