简体   繁体   English

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)]

Hibernate is unable to determine the type for Set at the table Company. Hibernate无法在表Company上确定Set的类型。 I am trying to create a foreign key of table Company through one-to-many relationship. 我正在尝试通过一对多关系创建表Company的外键。 One Company can have multiple users. 一个公司可以有多个用户。

Company.java is given below: Company.java如下所示:

@Entity
@Table(name = "Company")
@SuppressWarnings("serial")
public class Company implements Serializable {


    @Id
    @GeneratedValue
    @Column(name = "companyId", length = 32 )
    private int companyId;

    private Set<User> users;

    @Column(name = "companyName")
    String companyName;

    @Column(name = "typeOfBusiness")
    String typeOfBusiness;


    public int getCompanyId() {
        return companyId;
    }

    public void setCompanyId(int id) {
        this.companyId = id;
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public String getTypeOfBusiness() {
        return typeOfBusiness;
    }

    public void setTypeOfBusiness(String typeOfBusiness) {
        this.typeOfBusiness = typeOfBusiness;
    }


    public Set<User> getUsers() {
        return this.users;
    }

    @OneToMany(mappedBy="company", cascade=CascadeType.ALL, fetch=FetchType.LAZY, orphanRemoval=true)
    public void setUsers(Set<User> users) {
        this.users = users;
    }

    public Company() {
    }

    public Company(int companyId, Set<User> users, String companyName, String typeOfBusiness) {
        this.companyId = companyId;
        this.users = users;
        this.companyName = companyName;
        this.typeOfBusiness = typeOfBusiness;
    }
}

User.java is as below: User.java如下:

@Entity
@Table(name = "User")
@SuppressWarnings("serial")
public class User implements Serializable {

    @Id
    @GeneratedValue
    @Column(name = "id", length = 11 )
    private Long id;

    private Company company;

    @Column(name = "userName")
    String userName;

    @Column(name = "userPassword")
    String userPassword;

    @Column(name = "userEmail")
    String userEmail;


    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    } 

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getUserPassword() {
        return userPassword;
    }

    public void setUserPassword(String userPassword) {
        this.userPassword = userPassword;
    }

    public String getUserEmail() {
        return userEmail;
    }

    public void setUserEmail(String userEmail) {
        this.userEmail = userEmail;
    }

    public Company getCompany() {
        return this.company;
    }

    @ManyToOne
    @JoinColumn( name="companyId",insertable=false, updatable=false, nullable = false)
    public void setCompany(Company company) {
        this.company = company;
    }

    public User(){}

    public User(Long id, Company company, String userName, String userPassword, String userEmail) {
        super();
        this.id = id;
        this.company = company;
        this.userName = userName;
        this.userPassword = userPassword;
        this.userEmail = userEmail;
    }
}

And below is my database definition for mysql: 下面是我对mysql的数据库定义:

CREATE TABLE `Company` (                   
          `companyId` bigint(32) NOT NULL AUTO_INCREMENT,  
          `companyName` varchar(50) NOT NULL,
          `typeOfBusiness` varchar(50),
          PRIMARY KEY (`companyId`)                     
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `User` (                   
          `id` int(11) NOT NULL AUTO_INCREMENT,  
          `userName` varchar(50) NOT NULL,      
          `userPassword` varchar(50) NOT NULL,
          `userEmail` varchar(50),
          `phoneNumber` bigint(32),
          `companyId` bigint(32),
          PRIMARY KEY (`id`),
          FOREIGN KEY (companyId) REFERENCES Company(companyId) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

you have to mention this relation at class level also in Company 您还必须在Company班级级别提及这种关系

@OneToMany(fetch = FetchType.LAZY, mappedBy = "company")
 private Set<User> users;

in User User

@ManyToOne
@JoinColumn(name="company_id")
private Company company;

暂无
暂无

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

相关问题 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.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(卖家)] - org.hibernate.MappingException: Could not determine type for: at table: for columns: [org.hibernate.mapping.Column(seller)] 引起:org.hibernate.MappingException:无法确定类型:时间戳,列:[org.hibernate.mapping.Column(***)] - Caused by: org.hibernate.MappingException: Could not determine type for: Timestamp, for columns: [org.hibernate.mapping.Column(***)] 使用@ElementCollection时出错:org.hibernate.MappingException:无法确定类型:java.util.Set,在表:对于列 - Error while using @ElementCollection: org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: for columns 无法构建 Hibernate SessionFactory; 嵌套异常是 org.hibernate.MappingException:无法确定类型:java.util.Set,在表中: - Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: 多对多关系:org.hibernate.MappingException:无法确定以下类型:java.util.Set - many to many relationship : org.hibernate.MappingException: Could not determine type for: java.util.Set 无法确定类型:java.util.List,在表:file_post,列:[org.hibernate.mapping.Column(file)] - Could not determine type for: java.util.List, at table: file_post, for columns: [org.hibernate.mapping.Column(file)]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM