[英]JPQL: Difference between EclipseLink and Hibernate
I already asked about my situation and didn't find a proper solution.我已经询问了我的情况,但没有找到合适的解决方案。 After some additional search I think I know the source problem although don't know how to resolve it.经过一些额外的搜索,我想我知道源问题,尽管不知道如何解决它。 As mentioned I have:如前所述,我有:
@Table(name = "role__parent")
@IdClass(RoleAssociationKey.class)
@Data
public class RoleAssociation implements Serializable {
@Id
@JoinColumn(name = "has_parent_role_id")
private Role node;
@Id
@JoinColumn(name = "is_parent_for_role_id")
private Role parent;
...
}
@Data
class RoleAssociationKey implements Serializable {
private static final long serialVersionUID = 1L;
private int node;
private int parent;
}
and I have我有
@Table(name = "role")
@Data
public class Role implements IRole {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@OneToMany(mappedBy = "node", orphanRemoval = true, cascade = { CascadeType.ALL })
private List<RoleAssociation> parentRoles;
...
Up to this point I think nothing special.到目前为止,我认为没有什么特别的。 I have the query:我有查询:
@NamedQuery(name = "Role.findParents", query =
"SELECT r FROM Role r JOIN RoleAssociation ra ON r.id = ra.parent.id WHERE ra.node.id = :id")
with the purpose to all set parents.目的是为了所有的父母。 When I compile it Hibernate complains left and right hand sides of a binary logic operator were incompatible [integer : component[node,parent]]
当我编译它时,Hibernate 抱怨left and right hand sides of a binary logic operator were incompatible [integer : component[node,parent]]
Since the statement works in EclipseLink I have no clue how to change it into a working Hibernate one.由于该语句在 EclipseLink 中有效,我不知道如何将其更改为有效的 Hibernate 语句。 Help would be highly appreciated.帮助将不胜感激。
After some struggels I finally figured the root cause of this problem.经过一番努力,我终于找到了这个问题的根本原因。 I'm aware that the SQL might be improved nevertheless I fail at other similar spots.我知道 SQL 可能会得到改进,但我在其他类似的地方失败了。
Hibernate requires to have a matching pair for @OneToMany
relation. Hibernate 需要为@OneToMany
关系提供匹配对。
In my query I refer to the parent
of my role.在我的查询中,我指的是我角色的parent
。 The solution is解决办法是
@Data
public class RoleAssociation implements Serializable {
@Id
@JoinColumn(name = "has_parent_role_id")
@ManyToOne // <<<<==== rerequired for Hibernate
private Role node;
@Id
@JoinColumn(name = "is_parent_for_role_id")
@ManyToOne // <<<<==== rerequired for Hibernate
private Role parent;
I have no clue why Hibernate complains while EclipseLink can fetch the required information.我不知道为什么 Hibernate 会抱怨而 EclipseLink 可以获取所需的信息。 Nevertheless with this additional annoation the code works!不过有了这个额外的注释,代码就可以工作了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.