组合主键——实体类——Oracle数据库
程序员文章站
2022-06-02 16:48:44
...
@Entity
@Table(name = "XXXX")
public class RolePrivilegeMap implements CmsMainBo {
private RolePrivilegeMapId id;
@EmbeddedId
public RolePrivilegeMapId getId() {
return id;
}
public void setId(RolePrivilegeMapId id) {
this.id = id;
}
public RolePrivilegeMap() {
}
}
@Entity
@Embeddable
public class RolePrivilegeMapId implements XXXXBo {
private static final long serialVersionUID = 2L;// 序列化ID
private Integer roleId;
private Integer privilegeInfoId;
public RolePrivilegeMapId(Integer roleId, Integer privilegeInfoId) {
super();
this.roleId = roleId;
this.privilegeInfoId = privilegeInfoId;
}
@Column(name = "role_id", unique = false, nullable = false)
public Integer getRoleId() {
return roleId;
}
public void setRoleId(Integer roleId) {
this.roleId = roleId;
}
@Column(name = "privilege_info_id", unique = false, nullable = false)
public Integer getPrivilegeInfoId() {
return privilegeInfoId;
}
public void setPrivilegeInfoId(Integer privilegeInfoId) {
this.privilegeInfoId = privilegeInfoId;
}
@Override
public int hashCode() {
final int prime = 32;
int result = 1;
result = prime * result + ((roleId == null) ? 0 : roleId.hashCode());
result = prime * result + ((privilegeInfoId == null) ? 0 : privilegeInfoId.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return false;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
RolePrivilegeMapId other = (RolePrivilegeMapId)obj;
if (roleId == null) {
if (other.roleId != null)
return false;
} else if (!roleId.equals(other.roleId))
return false;
if (privilegeInfoId == null) {
if (other.privilegeInfoId != null)
return false;
} else if (!privilegeInfoId.equals(other.privilegeInfoId))
return false;
return true;
}
}
if (privilegeInfos != null && rolePrivilegeMaps != null) {
privilegeInfoImpl.saveAll(privilegeInfos);
privilegeInfoImpl.flush();
for (PrivilegeInfo info: privilegeInfos){
RolePrivilegeMap rolePrivilegeMap = new RolePrivilegeMap();
rolePrivilegeMap.setId(new RolePrivilegeMapId(roleId,info.getPrivilegeInfoId()));
rolePrivilegeMaps.add(rolePrivilegeMap);
}
privilegeInfoImpl.saveAll(rolePrivilegeMaps);
privilegeInfoImpl.flush();
}
推荐阅读
-
Oracle 数据库针对表主键列并发导致行级锁简单演示
-
JDBC获得oracle数据库主键值
-
Oracle 数据库针对表主键列并发导致行级锁简单演示
-
Oracle数据库下给表设置自增的逻辑主键的方法
-
Oracle数据库中创建自增主键的实例教程
-
ORACLE数据库创建表、自增主键、外键相关语法讲解
-
如何得到JDBC Insert 语句执行后插入Oracle 数据库记录的主键
-
mybatis 插入时返回刚插入记录的主键值 (Oracle作为数据库)
-
mybatis 插入时返回刚插入记录的主键值 (Oracle作为数据库)
-
oracle数据库中查询该某个表的主键被哪些表引用及该表中的外键来源于哪些表