Java JPA 鉴别器值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20096118/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JPA Discriminator Value
提问by Yakaryo
I have a problem with JPA and Discriminator Value.
value=0 should be mapped as a user
and value=1 should be mapped as a admin
but I only get the users
我有 JPA 和鉴别器值的问题。value=0 应该映射为 auser
并且 value=1 应该映射为 aadmin
但我只得到用户
@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 {
采纳答案by jdev
Your usergroup is string and you set discriminatorType = DiscriminatorType.INTEGER
您的用户组是字符串并且您设置了 discriminatorType = DiscriminatorType.INTEGER
@Column(name="usergroup")
private String usergroup;
Change userGroup type to integer and if it is string in your database (type of userGroup field in table) then removediscriminatorType = DiscriminatorType.INTEGER
将 userGroup 类型更改为整数,如果它是数据库中的字符串(表中 userGroup 字段的类型),则删除discriminatorType = DiscriminatorType.INTEGER
@DiscriminatorColumn(name="usergroup")
because defalut of discriminatorType is string.
因为 discriminatorType 的默认值是字符串。