@Hibernate中的MappedSuperClass=AnnotationException:未知的mappedBy

@Hibernate中的MappedSuperClass=AnnotationException:未知的mappedBy,hibernate,mappedsuperclass,Hibernate,Mappedsuperclass,错误: 原因:org.hibernate.AnnotationException:com.xxx.data.dao.classes.Categories.categoriesLang中的未知映射,引用的属性未知:com.xxx.data.dao.classes.superclasses.categoriesLang.Categories 我的设置: 休眠3.5.6 public interface CategoriesLangInt { int id_categories = 0;

错误: 原因:org.hibernate.AnnotationException:com.xxx.data.dao.classes.Categories.categoriesLang中的未知映射,引用的属性未知:com.xxx.data.dao.classes.superclasses.categoriesLang.Categories

我的设置:

休眠3.5.6

public interface CategoriesLangInt {

    int id_categories = 0;
    Categories categories = null;
    String name = "";
    String description = "";

    int getId_categories();

    void setId_categories(int id_categories);

    Categories getCategories();

    void setCategories(Categories categories);

    String getName();

    void setName(String name);

    String getDescription();

    void setDescription(String description);
}


更新解决了它

经过长时间的研究,我终于成功了。很好用

@Entity
@Table(name="categories")
public class Category implements Serializable {

    private Integer id;
    private boolean active;

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

}






我认为这是因为您的超类(这里是接口)中的字段被扩展类中类似命名的字段所遮蔽。尝试从界面中删除这些字段(如类别)

首先,接口不能定义字段,只能定义方法。您在接口中声明的字段实际上是公共静态final常量

之后,Categories实体有一个CategoriesLangInt字段,但Hibernate无法知道该字段代表哪个实体,因为可能有多个实体实现了该接口。必须使用OneTONE注释的
targetEntity
属性告诉Hibernate引用了哪个实体

最后,CategoriesLang中的
id\u categories
列被映射两次:一次作为id,一次作为JoinColumn。您必须删除
id\u categories
字段并用@id注释
categories
字段,或者保持
id\u categories
字段不变,并将@MapsId注释添加到
categories

旁注:您应该遵守Java命名约定(字段和方法中没有下划线),并将Categories重命名为Category,CategoriesLang重命名为CategoryLang,等等

@Entity
@Table(name="categories")
public class Categories implements Serializable {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Integer id_categories;
    private boolean active;
    @OneToOne(mappedBy="categories")
    private CategoriesLangInt categoriesLangInt;

    public Integer getId_categories() {
        return id_categories;
    }

    public void setId_categories(Integer id_categories) {
        this.id_categories = id_categories;
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public CategoriesLangInt getCategoriesLangInt() {
        return categoriesLangInt;
    }

    public void setCategoriesLangInt(CategoriesLangInt categoriesLangInt) {
        this.categoriesLangInt = categoriesLangInt;
    }

}
@Entity
@Table(name="categories")
public class Category implements Serializable {

    private Integer id;
    private boolean active;

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

}
public interface CategoryInt{

    int getCategory_id();

    void setCategory_id(int category_id);

    String getName();

    void setName(String name);

    String getDescription();

    void setDescription(String description);

    void setCategory(Category category);

    Category getCategory();
}
@MappedSuperclass
public abstract class CategoryLang implements CategoryInt{

    private int category_id;
    private String name;
    private String description;
    private Category category;

    @Override
    @Id
    public int getCategory_id() {
        return category_id;
    }

    @Override
    public void setCategory_id(int category_id) {
        this.category_id = category_id;
    }

    @Override
    @Size(max = 50)
    public String getName() {
        return name;
    }

    @Override
    public void setName(String name) {
        this.name = name;
    }

    @Override
    @Size(max = 350)
    public String getDescription() {
        return description;
    }

    @Override
    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    @OneToOne(cascade = CascadeType.ALL)
    @PrimaryKeyJoinColumn
    public Category getCategory() {
        return category;
    }

    @Override
    public void setCategory(Category category) {
        this.category = category;
    }
}
@Entity
@Table(name = "en_categories")
public class CategoryEN extends CategoryLang implements Serializable {}
@Entity
@Table(name = "es_categories")
public class CategoryES extends CategoryLang implements Serializable {}