Spring ManyToOne注解
?
代码一:
@Entity@Table(name="KS_ROLE_USER_AUTH")public class RoleUserAuthorization extends Accountability{ @ManyToOne @JoinColumn(name="ROLE_ID", nullable=false) private Role role; @ManyToOne @JoinColumn(name="USER_ID", nullable=false) private User user;
?
代码二:
@Entity@Table(name="KS_ROLE")@DiscriminatorColumn(name="role", discriminatorType=DiscriminatorType.STRING)public class Role extends Identity{ private static final long serialVersionUID = -8345993710464457036L; @Column(name="ROLE_DESC") private String roleDesc; @OneToMany(fetch=FetchType.LAZY, mappedBy="role") private List<RoleUserAuthorization> roleUsers; public List<RoleUserAuthorization> getRoleUsers() { return this.roleUsers; } public void setRoleUsers(List<RoleUserAuthorization> roleUsers) { this.roleUsers = roleUsers; }
?
代码三:
@Entity@Table(name="KS_USER")@DiscriminatorColumn(name="User", discriminatorType=DiscriminatorType.STRING)public class User extends Identity{ private static final long serialVersionUID = 1828900234948658820L; @Column(name="LAST_LOGIN_TIME") @Temporal(TemporalType.TIMESTAMP) private Date lastLoginTime; @Column(name="USER_ACCOUNT") private String userAccount; @Column(name="USER_PASSWORD") private String userPassword; @Column(name="USER_DESC") private String userDesc; @Column(name="LAST_MODIFY_TIME") private Date lastModifyTime; public Set<RoleUserAuthorization> getRoles() { return new HashSet(RoleUserAuthorization.findAuthorizationByUser(this)); }
?
?
单向关系中的JoinColumn?
joinColumns={ @JoinColumn(name="customer_id",referencedColumnName="id")}
?
?@JoinTable和@JoinColumn?领域层业务开发//查找某个年龄段内的员工public static List<Employee> findByAgeRange(Integer from, Integer to) { return getRepository().findByNamedQuery("findEmployeesByAgeRange", new Object[]{from, to}, Employee.class);}??