如何在超类中创建数据库列注释,而不是使用JPA创建子类?

时间:2018-06-11 23:13:07

标签: java jpa inheritance annotations

以下是我正在处理的代码。 这是超类。

public abstract class Person extends Entity {

private final StringProperty name = new SimpleStringProperty(this, "name");
private final StringProperty gender = new SimpleStringProperty(this, "gender");
private final ObjectProperty<LocalDate> dateAdded = new SimpleObjectProperty<>(this, "dateAdded");

//I want to map this to a database column
public final String getName() {
    return name.get();
}

public final void setName(String value) {
    name.set(value);
}

public StringProperty nameProperty() {
    return name;
}

public final String getGender() {
    return gender.get();
}

public final void setGender(String value) {
    gender.set(value);
}

public StringProperty genderProperty() {
    return gender;
}

public final LocalDate getDateAdded() {
    return dateAdded.get();
}

public final void setDateAdded(LocalDate value) {
    dateAdded.set(value);
}

public ObjectProperty<LocalDate> dateAddedProperty() {
    return dateAdded;
}

这是它的子类。

@javax.persistence.Entity
@Table(name="admins")
public class Admin extends Person{
private final StringProperty username = new SimpleStringProperty(this, "username");
private final StringProperty password = new SimpleStringProperty(this, "password");

public final String getUsername() {
    return username.get();
}

public final void setUsername(String value) {
    username.set(value);
}

public StringProperty usernameProperty() {
    return username;
}

public final String getPassword() {
    return password.get();
}

public final void setPassword(String value) {
    password.set(value);
}

public StringProperty passwordProperty() {
    return password;
}

}

所以我需要知道的是,是否可以在超类定义中创建表列注释,并且该注释应用了一个JPA实体的子类。请有人帮忙解决这个问题吗?

0 个答案:

没有答案