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.

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

2 Comments

I added this annotation right now, but its still the same exception
Have you tried any of the following answer from here stackoverflow.com/questions/3983135/… ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.