简体   繁体   English

org.hibernate.MappingException:无法确定类型:在表中:列:[org.hibernate.mapping.Column(卖家)]

[英]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.我的问题出在 Product.class 和 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:这是代码:产品 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:用户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.正如您可以在内部错误中看到的那样,您没有 map 关系的所有结束。

"Could not determine type for: com.chana.beans.User, at table: shipment, for columns: [org.hibernate.mapping.Column(seller)]" “无法确定类型:com.chana.beans.User,表:发货,列:[org.hibernate.mapping.Column(卖家)]”

This error suggest that you don't have correct relation mapping between User and Shipments entities.此错误表明您在 User 和 Shipments 实体之间没有正确的关系映射。

Btw.: It seems that you don't use @ElementCollection correctly - this annotation is used for embedded documents not entities, use @OneToMany.顺便说一句:您似乎没有正确使用@ElementCollection - 此注释用于嵌入文档而不是实体,请使用@OneToMany。

With @Data you dont need @Getter and @Setter- it is a shortcut for @Getter @Setter @EqualsAndHashcode and @RequiredArgsConstructor.使用@Data,您不需要@Getter 和@Setter——它是@Getter、@Setter、@EqualsAndHashcode 和@RequiredArgsConstructor 的快捷方式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.hibernate.MappingException:无法确定以下类型:表:对于列:[org.hibernate.mapping.Column(plant) - org.hibernate.MappingException: Could not determine type for: at table: for columns: [org.hibernate.mapping.Column(plant) 引起:org.hibernate.MappingException:无法确定类型:时间戳,列:[org.hibernate.mapping.Column(***)] - Caused by: org.hibernate.MappingException: Could not determine type for: Timestamp, for columns: [org.hibernate.mapping.Column(***)] org.hibernate.MappingException:无法确定类型:java.util.Set,在表:Company中,用于列:[org.hibernate.mapping.Column(users)] - org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: Company, for columns: [org.hibernate.mapping.Column(users)] org.hibernate.MappingException:无法确定类型:java.util.List,在表:大学,列:[org.hibernate.mapping.Column(students)] - org.hibernate.MappingException: Could not determine type for: java.util.List, at table: College, for columns: [org.hibernate.mapping.Column(students)] org.hibernate.MappingException:无法确定类型:java.util.List,在表:user处,用于列:[org.hibernate.mapping.Column(events)] - org.hibernate.MappingException: Could not determine type for: java.util.List, at table: user, for columns: [org.hibernate.mapping.Column(events)] org.hibernate.MappingException:无法确定类型:java.util.Collection,用于列:[org.hibernate.mapping.Column(lisOfAddresses)] - org.hibernate.MappingException: Could not determine type for: java.util.Collection, for columns: [org.hibernate.mapping.Column(lisOfAddresses)] 无法确定以下表的类型:org.json.JSONObject,在表:ordersinfo中,用于列:[org.hibernate.mapping.Column(items)] - Could not determine type for: org.json.JSONObject, at table: ordersinfo, for columns: [org.hibernate.mapping.Column(items)] org.hibernate.MappingException:无法确定以下类型: - org.hibernate.MappingException: Could not determine type for: org.hibernate.MappingException:无法确定类型 - org.hibernate.MappingException: Could not determine type for org.hibernate.MappingException:无法确定以下类型: - org.hibernate.MappingException: Could not determine type for:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM