[英]Joining two table entities in Spring Data JPA with where clause
I have been searching the answer for my question below, and nothing come up so far. 我一直在下面寻找我的问题的答案,到目前为止没有任何进展。
Quick explanation: 快速说明:
A person can has more than one roles, and role has many-to-many relationship with privilege. 一个人可以有多个角色,并且角色与特权之间具有多对多关系。
I have the entities, Role : 我有实体, 角色 :
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "ROLE")
@Where(clause = "RECORD_STATUS = 'A'")
@SQLDelete(sql = "UPDATE ROLE SET RECORD_STATUS = 'D' where OBJID = ?")
public class Role extends BaseEntity implements Serializable {
private String roleDescription;
private String roleName;
@JoinTable(
name = "ROLE_PRIVILEGE",
joinColumns = @JoinColumn(
name = "roleOid"
),
inverseJoinColumns = @JoinColumn(
name = "privilegeOid"
)
)
@Where(clause = "RECORD_STATUS = 'A'")
@ManyToMany(fetch = FetchType.EAGER)
List<Privilege> privileges;
}
Privilege entity: 特权实体:
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "PRIVILEGE")
@Where(clause = "RECORD_STATUS = 'A'")
@SQLDelete(sql = "UPDATE PRIVILEGE SET RECORD_STATUS = 'D' where OBJID = ?")
public class Privilege extends BaseEntity implements Serializable {
private String description;
private String privilegeName;
}
I wanted to join these 2 tables like this: 我想像这样加入这两个表:
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "ROLE_PRIVILEGE")
@Where(clause = "RECORD_STATUS = 'A'")
@SQLDelete(sql = "UPDATE ROLE_PRIVILEGE SET RECORD_STATUS = 'D' where OBJID
= ?")
public class RolePrivilege extends BaseEntity implements Serializable {
private String roleOid;
private String privilegeOid;
}
The problem is, when I try to get roles of a person, they all come with the privileges. 问题是,当我尝试获得一个人的角色时,它们都具有特权。 But, hibernate doesnt care the where clause in ROLE_PRIVILEGE entitiy:
但是,休眠并不关心ROLE_PRIVILEGE实体中的where子句:
select
privileges0_.role_oid as role_oid8_23_0_,
privileges0_.privilege_oid as privileg7_23_0_,
privilege1_.objid as objid1_21_1_,
privilege1_.creation_date as creation2_21_1_,
privilege1_.last_change_date as last_cha3_21_1_,
privilege1_.luc as luc4_21_1_,
privilege1_.record_status as record_s5_21_1_,
privilege1_.user_created as user_cre6_21_1_,
privilege1_.description as descript7_21_1_,
privilege1_.privilege_name as privileg8_21_1_
from
role_privilege privileges0_
inner join
privilege privilege1_
on privileges0_.privilege_oid=privilege1_.objid
where
(
privilege1_.RECORD_STATUS = 'A'
)
and privileges0_.role_oid=?
I mean, when I deactivate a role-privilege tuple(role does not have that privilege anymore), still comes to me. 我的意思是,当我停用角色特权元组(角色不再具有该特权)时,仍然会出现在我身上。 Where can I add the @where clause to ROLE_PRIVILEGE table to?
在哪里可以将@where子句添加到ROLE_PRIVILEGE表中?
all advises are much appriciated! 所有建议都非常有用!
I do not really know how I missed that but found the solution. 我真的不知道我怎么想念它,但是找到了解决方案。
@WhereJoinTable(clause = "RECORD_STATUS = 'A' ")
JPA @JoinTable with extra join conditions JPA @JoinTable具有额外的加入条件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.