Hibernate @OneToOne References an Unknown Entity E

2019-09-09 20:49发布

I'm having a hard time finding the root cause of an error where my @OneToOne mapping isn't working and is returning a "references an unknown entity" exception.

To start with I ensured that both classes are properly annotated with the @Entity tag. Also it is worth noting my Product.java class (which you will see below) worked fine and only encounters a problem when I try to attach a foreign key to my Project.java class referencing the Product.java class.

Java Code for Project.java and Product.java

@Entity
@Table (name="project")
@SequenceGenerator(name="seq_project",sequenceName="BI**********.SEQ_PROJECT", allocationSize=1, initialValue=1)
public class Project {

    //Fields
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq_project")
    @Column(name="PROJECT_ID")
    private int id;
    @Column(name="PROJECT_CODE")
    private String projectCode;
    @Column(name="PRODUCT_ID")
    private int productId;
    @Column(name="DESCRIPTION")
    private String description;

    @OneToOne(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
    //@PrimaryKeyJoinColumn
    @JoinColumn(name="PRODUCT.PRODUCT_ID")
    private Product product;


@Entity
@Table (name="PRODUCT")
@SequenceGenerator(name="seq_product",sequenceName="BI************.SEQ_PRODUCT", allocationSize=1, initialValue=1)
public class Product {

    //Fields
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq_product")
    @Column(name="PRODUCT_ID")
    private int productId;
    @Column(name="PRODUCT_NAME")
    private String productName;
    @Column(name="DESCRIPTION")
    private String description;
    @OneToOne(mappedBy="Project")
    @JoinColumn(name="PROJET_FK1")
    private Project project;

Here is the error code I'm getting:

Exception in thread "main" org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.manh.entries.Project.product references an unknown entity: com.manh.entries.Product

Thanks for any help and advice.

1条回答
冷血范
2楼-- · 2019-09-09 21:35

It's a configuration problem. Hibernate doesn't recognize class Product as a entity.

查看更多
登录 后发表回答