我有JPA和Discriminator Value的问题。
value = 0应映射为user
,value = 1应映射为admin
,但我只获取用户
@Entity
@Table(name="T_USERS")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="usergroup", discriminatorType = DiscriminatorType.INTEGER)
public abstract class UserModel implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="T_USERS_PK")
private int id;
@Column(name="username")
private String username;
@Column(name="password")
private String password;
@Column(name="firstname")
private String firstname;
@Column(name="lastname")
private String lastname;
@Column(name="usergroup")
private String usergroup;
-
@Entity
@DiscriminatorValue("0")
public class User extends UserModel {
-
@Entity
@DiscriminatorValue("1")
public class Admin extends UserModel {
答案 0 :(得分:3)
您的用户组是字符串,您设置了discriminatorType = DiscriminatorType.INTEGER
@Column(name="usergroup")
private String usergroup;
将userGroup类型更改为整数,如果它是数据库中的字符串(表中的userGroup字段的类型),则删除 discriminatorType = DiscriminatorType.INTEGER
@DiscriminatorColumn(name="usergroup")
因为discriminatorType的defalut是字符串。