@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class Problem {
@ManyToOne
private Person person;
}
@Entity
@DiscriminatorValue("UP")
public class UglyProblem extends Problem {}
@Entity
public class Person {
@OneToMany(mappedBy="person")
private List< UglyProblem > problems;
}
I think it is pretty clear what I'm trying to do. I expect the @ManyToOne person to be inherited by the UglyProblem class. But there will be an exception saying something like: "There is no such property (mappedBy =" person ") in the UglyProblem class."
All I found is this . I could not find a message from Emmanuel Bernard explaining the reasons for this.
Unfortunately, according to the Hibernate documentation, "Properties from superclasses not displayed as @MappedSuperclass are ignored."
Well, I think it means that if I have these two classes:
public class A {
private int foo;
}
@Entity
public class B extens A {
}
then the field foowill not be displayed for class B. This makes sense. But if I have something like this:
@Entity
public class Problem {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@Entity
public class UglyProblem extends Problem {
private int levelOfUgliness;
public int getLevelOfUgliness() {
return levelOfUgliness;
}
public void setLevelOfUgliness(int levelOfUgliness) {
this.levelOfUgliness = levelOfUgliness;
}
}
, UglyProblem id name, . (, , , ). :
CREATE TABLE "problem" (
"DTYPE" varchar(31) NOT NULL,
"id" bigint(20) NOT NULL auto_increment,
"name" varchar(255) default NULL,
"levelOfUgliness" int(11) default NULL,
PRIMARY KEY ("id")
) AUTO_INCREMENT=2;
:
, @ManyToOne UglyProblem.
, , , ManyToOne.
, . , . : "...":). , , . , .
.
( , : , hibernate 3. Jboss 4.0.something + hibernate ( ). Jboss 4.2.2, , "@OneToMany mappedBy", ...)