Reputation: 69
I receive an error like below and I do not know why?
Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on ##################.model.Orders.customerid references an unknown entity: java.lang.Long
Class Orders
@Entity
public class Orders {
@Id
@GeneratedValue
private Long orderid;
@JoinColumn(name = "customerid", referencedColumnName = "CustomerID")
@ManyToOne
private Long customerid;
@JoinColumn(name = "employeeid", referencedColumnName = "EmployeeID")
@ManyToOne
private Long employeeid;
private java.sql.Timestamp orderdate;
private java.sql.Timestamp requireddate;
private java.sql.Timestamp shippeddate;
@JoinColumn(name = "shipperid", referencedColumnName = "ShipperID")
@ManyToOne
private Long shipvia;
private Double freight;
private String shipname;
private String shipaddress;
private String shipcity;
private String shipregion;
private String shippostalcode;
private String shipcountry;
@OneToMany(mappedBy="orderid")
private List<OrderDetails> orderDetails;
Class Customers
@Entity
public class Customers {
@Id
@GeneratedValue
private Long customerid;
private String companyname;
private String contactname;
private String contacttitle;
private String address;
private String city;
private String region;
private String postalcode;
private String country;
private String phone;
private String fax;
@OneToMany(mappedBy="customerid")
private List<Orders> orders;
Relation between this two entities are described here
Please explain me what am I doing wrong?
Upvotes: 2
Views: 11511
Reputation: 116
I had this error recently but with an unknown entity.
Initial SessionFactory creation failed.org.hibernate.AnnotationException: @OneToOne or @ManyToOne on XXXX.Terminal.location references an unknown entity: XXXX.dc.Location
Feb 06, 2020 11:51:38 AM org.apache.catalina.core.StandardContext listenerStart
In my case I had to add a mapping of this entity to the "hibernate.cfg.xml"
<mapping class="XXXX.dc.Location"/>
Upvotes: 1
Reputation: 69
I found the reason after asking the question I apologize for the inconvenience. As You can see I forgot to change type for customerid it should by as follows
Class Orders
@Entity
public class Orders {
@Id
@GeneratedValue
private Long orderid;
@JoinColumn(name = "customerid", referencedColumnName = "CustomerID")
@ManyToOne
private Customers customerid;
@JoinColumn(name = "employeeid", referencedColumnName = "EmployeeID")
@ManyToOne
private Employees employeeid;
private java.sql.Timestamp orderdate;
private java.sql.Timestamp requireddate;
private java.sql.Timestamp shippeddate;
@JoinColumn(name = "shipperid", referencedColumnName = "ShipperID")
@ManyToOne
private Shippers shipvia;
private Double freight;
private String shipname;
private String shipaddress;
private String shipcity;
private String shipregion;
private String shippostalcode;
private String shipcountry;
@OneToMany(mappedBy="orderid")
private List<OrderDetails> orderDetails;
Upvotes: 2