0

The scenario is following: I'm implementing a shopping cart, where a Customer can choose products from a product catalog, using Hibernate.

I get this exception, but I have no idea what I am doing wrong.

Exception in thread "main" java.lang.ExceptionInInitializerError, Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.OrderManagementMaven.bo.ShoppingcartItem.customer references an unknown entity: com.OrderManagementMaven.bo.Customer

at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:100) at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processEndOfQueue(InFlightMetadataCollectorImpl.java:1823) at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processFkSecondPassesInOrder(InFlightMetadataCollectorImpl.java:1767) at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1655) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:295) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:86) at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:479) at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:85) at com.OrderManagementMaven.HibernateUtil.(HibernateUtil.java:15)

This is my code:

@Entity
@Table(name = "SHOPPINGCART_ITEM")  
public class ShoppingcartItem {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private long itemId;
    
    @ManyToOne
    @JoinColumn(name="PRODUCTID")
    private Product product;
    
    @ManyToOne
    @JoinColumn(name="CUSTOMERID")
    private Customer customer;
    
    private int amount;
    //...
}
@Entity
@Table(name = "PRODUCTCATALOG")  
public class Product {
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private long id;
    private double price;
    private String
    //...
}
@Entity  
@Table(name = "CUSTOMER")  
public class Customer{
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private long id;
    @Column(name="CUSTOMERFIRSTNAME")
    private String firstname;
    @Column(name="CUSTOMERLASTNAME")
    private String lastname;
    //...
}

I don't think the error is in the annotations, because I changed them a few times and still got the same exception.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Steve450
  • 113
  • 2
  • 7

1 Answers1

1

Given the error message, could it be the case that the customer entity is not included in the scanned packages, specified e.g. within an @EntityScan annotation?

fladdimir
  • 1,230
  • 1
  • 5
  • 12
  • I added this annotation right now, but its still the same exception – Steve450 Jun 02 '21 at 09:55
  • 2
    Have you tried any of the following answer from here https://stackoverflow.com/questions/3983135/hibernate-manytoone-references-an-unknown-entity ? – Pilpo Jun 02 '21 at 11:50