我有三个表AB和C.现在我想在HQL中执行这个SQL查询:
select * from A as a
left join
B as b
on
a.id = b.id
left join
C as c
on
b.type=c.type;
Run Code Online (Sandbox Code Playgroud)
在编写等效的HQL时需要帮助.我试过这个HQL ......
Query q = session.createQuery(
"FROM A as a
LEFT JOIN
B as b
on
a.id=b.id
LEFT JOIN
C as c
on
b.type=c.type");
Run Code Online (Sandbox Code Playgroud)
这个查询抛出异常.....
org.hibernate.hql.ast.QuerySyntaxError:意外令牌:LEFT靠近第1行,第23列[FROM com.admin.A作为LEFT JOIN B作为b,其中a.Id = b.Id LEFT JOIN C作为c其中b.位于org.hibernate.hql的org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:74)org.hibernate.hql上的org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:214)中的类型= c.type位于org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:414)的org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)上的.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:127)
我也试过"with"和"on"子句而不是在哪里......我在"on"或"with"上得到了相同的意外标记
例外qith ON .....
org.hibernate.hql.ast.QuerySyntaxError:意外令牌:ON第1行,第41列[FROM com.admin.A作为LEFT JOIN B,b为a.Id = b.Id LEFT JOIN C as c onb.type在org.hibernate.hql上的org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:74)org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:214)中.= c.type]. ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:127)org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:414)
我也尝试使用"with"子句而不是在哪里......我得到了相同的意外标记或"with"
异常qith WITH …
hql ×1