Hibernate to get a list of primitive integers for a subproblem

Is there no way with Hibernate to return a list of (primitive) values ​​from a single column in a table? I need this for a subquery where I only want rows where a particular field is not in the ids list from another table.

0


a source to share


3 answers


well it turned out to be as simple as something like 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 searching on google but i was concerned that it might be specific NHibernate



from Eg.DomesticCat as cat where cat.Name not in ( 
select name.NickName from Eg.Name as name )

      

+2


a source


Can you use the original SQLQuery to hibernate?



SQLQuery q = getSession().createSQLQuery("select int_column from table");
List<Integer> list = (List<Integer>) q.list();

      

+3


a source


Don't know how to use the hibernate engine itself, I think it will depend on how you mapped the model objects without waiting for the mapping, you can go through 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 in the request and use autoboxing on the primtive int array.

0


a source







All Articles