EJB-QL 3 中的 MEMBER OF 不起作用
我想检索许多具有一个共同“角色”的“访问”。
这是命名查询:
SELECT access
FROM Access AS access
WHERE :role MEMBER OF access.listRole
Access 实体
public class Access implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
private String name;
private String libelle;
@ManyToOne
private Module oneModule;
@ManyToMany
private List<Role> listRole;
/* Setter & Getter */
}
Role 实体
public class Role implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
private String name;
private String description;
@Enumerated(EnumType.STRING)
private Flag oneFlag;
@Transient
private int lengthAccess;
@OneToMany(mappedBy="oneRole")
private List<UserAccount> listUserAccount;
@ManyToMany
private List<Access> listAccess;
/* Geter & Setter */
}
但我没有实现正确的 EJB-QL !
配置:
- EJB 3
- MySQL (InnoDB)
- jBoss
- Plop
谢谢。
I would like to retrieve many 'Access' which have one 'Role' in common.
It's the named query:
SELECT access
FROM Access AS access
WHERE :role MEMBER OF access.listRole
The Access entity
public class Access implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
private String name;
private String libelle;
@ManyToOne
private Module oneModule;
@ManyToMany
private List<Role> listRole;
/* Setter & Getter */
}
The Role entity
public class Role implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
private String name;
private String description;
@Enumerated(EnumType.STRING)
private Flag oneFlag;
@Transient
private int lengthAccess;
@OneToMany(mappedBy="oneRole")
private List<UserAccount> listUserAccount;
@ManyToMany
private List<Access> listAccess;
/* Geter & Setter */
}
But I don't achieve to do the right EJB-QL !
Configuration:
- EJB 3
- MySQL (InnoDB)
- jBoss
- Plop
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我无法重现该问题。运行您提供的 JPQL 查询时,如下所示:
Hibernate 为我生成以下 SQL 查询(我通过删除一些属性简化了您的实体):
一切似乎都是正确的(使用 Hibernate Core 3.3.0.SP1、Hibernate Annotations 3.4 进行测试)。 0.GA,Hibernate EM 3.4.0.GA)
您使用的到底是什么版本的 Hibernate(核心、注释、EntityManager)?你到底得到了什么错误?您能展示如何调用查询吗?
I cannot reproduce the problem. When running the JPQL query you provided, like this:
Hibernate generates the following SQL query for me (I simplified a bit your entities by removing some attributes):
Everything seems correct (tested with Hibernate Core 3.3.0.SP1, Hibernate Annotations 3.4.0.GA, Hibernate EM 3.4.0.GA)
What version of Hibernate (Core, Annotations, EntityManager) are you using exactly? What error do you get exactly? Can you show how you invoke the query?
我的两个类之间的链接@ManyToMany没有以正确的方式编写,在项目构建期间,在MySQL中创建了2个表(“access_role”为我的链接@ManyToMany在“access”类中,role_access为我的链接@ “角色”类中的ManyToMany)
因此,为了纠正这个问题,我进行了这样的修改
My link @ManyToMany between my two classes isn't write in the right way, during the project's building, 2 Tables has created in MySQL ("access_role" for my link @ManyToMany in the 'access' class, and role_access for my link @ManyToMany in the 'role' class)
So, to correct this, I modified like this