我正在研究Hibernate项目,我不知道如何在不添加其他列的情况下获得鉴别器的价值?
<class name="gestion.commande.modele.Personne" table="personne" dynamic-update="true" lazy="false">
<id name="identifiant" type="int" column="IDENTIFIANT">
<generator class="increment" />
</id>
<discriminator column="TYPE" type="string"/>
<property name="nom" type="string" column="NOM" />
<property name="prenom" type="string" column="PRENOM" />
<property name="login" type="string" column="LOGIN" />
<property name="password" type="string" column="PASSWORD" />
<subclass name="gestion.commande.modele.Client" discriminator-value="client">
<property name="adresse" type="string" column="ADRESSE" />
<bag name="commandes" cascade="all" lazy="false">
<key column="IDCLIENT" />
<one-to-many class="gestion.commande.modele.Commande" />
</bag>
</subclass>
<subclass name="gestion.commande.modele.Administrateur" discriminator-value="Administrateur" />
</class>
这是我的模特:
public class Personne {
protected int identifiant;
protected String nom;
protected String prenom;
protected String login;
protected String password;
protected String type;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Personne() {
}
public Personne(String nom, String prenom, String login, String password,
String type) {
super();
this.nom = nom;
this.prenom = prenom;
this.login = login;
this.password = password;
this.type = type;
}
public Personne(String nom, String prenom) {
this.nom = nom;
this.prenom = prenom;
}
public int getIdentifiant() {
return identifiant;
}
public void setIdentifiant(int identifiant) {
this.identifiant = identifiant;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getPrenom() {
return prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
当我从数据库加载Personne并调用getType时,它返回NULL
答案 0 :(得分:0)
尝试将 discriminator 列的名称写为:
<discriminator column="type" type="string"/>