简体   繁体   中英

org.hibernate.MappingException: Could not determine type for: at table: for columns: [org.hibernate.mapping.Column(seller)]

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM