我有 3 张 table :
用户 ->>- 多对多 ->>- Userapp ->>- 多对多 ->>- 应用程序
用户拥有:
用户ID
用户名
UserApp:
用户ID
applicationId
应用:
applicationId
应用程序名称
我没有成功创建返回一个特定用户的每个应用程序的 HQL 查询。
我的 HQL:
select a.userId, a.userName from Application b join b.userId a where b.userId = 1
简化我想做的查询:来自应用程序 WHERE Userapp.userID = 1
你能帮我吗:)?
编辑:
我的工具:
Netbean 8.x
Hibernate 插件
第二个错误:org.hibernate.hql.internal.ast.QuerySyntaxException:Userapp未映射
当我从数据库创建 hibernate 映射文件和 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 = ?
关于mysql - 3 个表之间的 HQL 多对多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30123308/