Hibernate, selecting all rows of a table (using. *), Joins with multiple tables, providing an exception

Is it possible to do this with Hibernate?

select A.something, B.something, C.something, D.something , E.* from A LEFT OUTER JOIN B on A.id = B.id_fk LEFT OUTER JOIN C ON B.id = C.id_fk LEFT OUTER JOIN D ON C.id = D.id_fk LEFT OUTER JOIN E ON A.abc = E.abc; 

This query works fine in SQL, but gives the following exception in sleep mode:

 org.hibernate.hql.ast.QuerySyntaxException: expecting IDENT, found '*' near line 1 
+8
source share
2 answers

You do not need "*". hibernate rotates objects * does not make sense since it points to columns in SQL. When you want E, it rotates object E.

SELECT E FROM E

this is HQL for SELECT * FROM E

even "FROM E" works when you call session.createQuery ().

+14
source

HQL query is different - SQL -

Choose * from A;

HQL -

of

SQL -

select b, c, d from A

HQL -

select b, c, d from A

 org.hibernate.Query query = createQuery("select b FROM aaaa"); query.setReadOnly(true); return (List<Vector<aaaa>>)query.list(); 

https://docs.jboss.org/hibernate/orm/3.3/reference/en/html/queryhql.html

0
source

All Articles