0

I tried to find the solution in other questions, but it doesn't help me.

this is a small program, with some classes. my problem is in the relationship between Product.class and User.class. but I don't know how to resolve it. I get this error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not determine type for: com.chana.beans.User, at table: shipment, for columns: [org.hibernate.mapping.Column(seller)]

this is the code: Product class:

@Entity
@Table(name= "products")
public class Product {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;
    @Column
    private String title;
    private String description;
    @ManyToOne
    @JoinColumn(name="category_id")
    private Category category;
    private double price;
    @ManyToOne(targetEntity = User.class,  
            cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @Access(AccessType.PROPERTY)
    @JoinColumn(name="seller_id")
    private User seller;
    private String size;
    private String color;
    private String material;
    private int amount;

//getter and setter...

User class:

@Data
@NoArgsConstructor
@Builder
@AllArgsConstructor
@Setter
@Getter
@Entity
@Table(name= "users")
public class User {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private long id;
    @Column(name="first_name")
    private String firstName;
    @Column(name="last_name")
    private String lastName;
    private String Address;
    private String City;
    private String email;
    @Column(name="user_name")
    private String userName;
    private String password;
    @ElementCollection
    private List<Product> products;
    

What is the cause of the error, and how to fix it?

2
  • 1
    It says about "at table: shipment" and you provided the code for table "Product". What is the code of Shipment entity? Commented May 8, 2022 at 19:57
  • 1
    its was all the time product table :) meybe I resolved it and didn't pay attention that I already resolved it in the product table, and now need to do the same in the shipment table. so thank you for your attention !! Commented May 8, 2022 at 20:11

1 Answer 1

1

As you can read inside error you didn't map all ends of relations.

"Could not determine type for: com.chana.beans.User, at table: shipment, for columns: [org.hibernate.mapping.Column(seller)]"

This error suggest that you don't have correct relation mapping between User and Shipments entities.

Btw.: It seems that you don't use @ElementCollection correctly - this annotation is used for embedded documents not entities, use @OneToMany.

With @Data you dont need @Getter and @Setter- it is a shortcut for @Getter @Setter @EqualsAndHashcode and @RequiredArgsConstructor.

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

Comments

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.