我有3张桌子:
用户->>-多对多->>- Userapp ->>-多对多->>-应用
用户有:
用户身份
用户名
UserApp:
用户身份
applicationId
适用范围:
applicationId
applicaitonName
我没有成功创建一个返回一个特定用户的每个Application的HQL查询。
我的总部:
select a.userId, a.userName from Application b join b.userId a where b.userId = 1
简化查询,我想做: from Application WHERE Userapp.userID = 1
请问你能帮帮我吗 :) ?
编辑 :
我的工具:
Netbean 8.x
Hibernate插件
第二个错误: org.hibernate.hql.internal.ast.QuerySyntaxException: Userapp is not mapped
当我从数据库创建休眠映射文件和POJO时,将创建2个对象:用户和应用程序。但不是关联表“ Userapp”
我的hibernate.reveng.xml:
<hibernate-reverse-engineering>
<schema-selection match-catalog="allin"/>
<table-filter match-name="user"/>
<table-filter match-name="application"/>
<table-filter match-name="userapp"/>
</hibernate-reverse-engineering>
问候
我认为您的查询应如下所示:
SELECT a.applicaitonName
FROM User u
LEFT JOIN UserApp ua ON u.userId= ua.userId
LEFT JOIN Application a On ua.applicationId= a.applicationId
WHERE
u.userName = ?
或者
SELECT a.applicaitonName
FROM UserApp ua
LEFT JOIN Application a On ua.applicationId= a.applicationId
WHERE
ua.userId = ?
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句