我正在使用休眠条件查询框架来生成报告。我还必须提供排序和过滤。当数据仅限于单个实体时,一切正常。但是,我需要加入多个实体并将结果显示在一个表中。以下是实体:
@Entity
@Table(name = "user_profile")
@Where(clause = "deleted = 0")
public class UserProfile {
@GeneratedValue(strategy = GenerationType.AUTO)
Long id;
@Column(name = "username")
private String username;
@Column(name = "email")
private String email;
@Column(name = "first_name")
private String firstName;
@Column(name = "middle_name")
private String middleName;
@Column(name = "last_name")
private String lastName;
}
@Entity
@Table(name = "user_data")
public class UserData {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "username")
private String username;
@Column(name = "password")
private String password;
@Column(name = "account_nonexpired")
private Boolean accountNonExpired = true;
@Column(name = "account_nonlocked")
private Boolean accountNonLocked = true;
@Column(name = "credentials_nonexpired")
private Boolean credentialsNonExpired = true;
@Column(name = "enabled")
private Boolean enabled = false;
}
@Entity
@Table(name = "user_role")
public class Role {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "username")
private String username;
@Column(name = "role")
private String role;
}
这些实体有一个共同的用户名。是否可以创建一个没有表但仅包含这些实体作为字段的实体?例如:
public Class UserDataProfileRoleMapping{
private UserProfile userProfile;
private List<Role> role;
private UserData userData;
}
我可以创建一个映射表,但我把它作为最后的手段。
编辑
我要触发的查询类似于:
select * from user_data u, user_role r, user_profile up
where
u.username = r.username and
r.username = up.username;