Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot PropertyAccessException:调用模型id的getter时发生IllegalArgumentException_Spring Boot_Hibernate_Jpa - Fatal编程技术网

Spring boot PropertyAccessException:调用模型id的getter时发生IllegalArgumentException

Spring boot PropertyAccessException:调用模型id的getter时发生IllegalArgumentException,spring-boot,hibernate,jpa,Spring Boot,Hibernate,Jpa,我到处都找过了,但我不明白我做错了什么-在我尝试在我的表中进行内部联接之后,我得到了这个异常,这是我得到的错误消息 "IllegalArgumentException occurred calling getter of com.userservice.usermanagement.models.Role2.id; nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException oc

我到处都找过了,但我不明白我做错了什么-在我尝试在我的表中进行内部联接之后,我得到了这个异常,这是我得到的错误消息

"IllegalArgumentException occurred calling getter of com.userservice.usermanagement.models.Role2.id; nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.userservice.usermanagement.models.Role2.id"
这些是我的模型:- 使用者

@实体
@表(name=“users”)
公共类用户2{
/**
*用户模型
*/ 
私人长id;
私有字符串用户名;
私人字符串电子邮件;
私有字符串密码;
私有字符串客户名称;
私有字符串customerid;
私有字符串描述;
私有集角色=新HashSet();
公共用户2(){
}
public User2(字符串用户名、字符串电子邮件、字符串customername、字符串customerid、字符串描述、字符串密码){
this.username=用户名;
this.email=电子邮件;
this.customername=客户名称;
this.customerid=customerid;
this.description=描述;
this.password=密码;
} 
@身份证
@GeneratedValue(策略=GenerationType.IDENTITY)
公共长getId(){
返回id;
}
公共无效集合id(长id){
this.id=id;
}
@列(name=“username”,null=false,长度=1024)
公共字符串getUsername(){
返回用户名;
}
public void setUsername(字符串用户名){
this.username=用户名;
}
@列(name=“email”,null=false,长度=1024)
公共字符串getEmail(){
回复邮件;
}
公用电子邮件(字符串电子邮件){
this.email=电子邮件;
}
@列(name=“password”,null=false,长度=1024)
公共字符串getPassword(){
返回密码;
}
public void setPassword(字符串密码){
this.password=密码;
}
@列(name=“customername”,null=false,长度=1024)
公共字符串getCustomername(){
返回客户名称;
}
public void setCustomername(字符串customername){
this.customername=客户名称;
}
@列(name=“customerid”,null=false,长度=1024)
公共字符串getCustomerid(){
返回客户ID;
}
public void setCustomerid(字符串customerid){
this.customerid=customerid;
}
@列(name=“description”,null=false,长度=1024)
公共字符串getDescription(){
返回说明;
}
公共void集合描述(字符串描述){
this.description=描述;
}
@manytone(targetEntity=Role2.class)
@JoinColumn(name=“role”)
公共集getRoles(){
返回角色;
}
公共无效集合角色(集合角色){
this.roles=角色;
}
}
角色

@实体
@表(name=“roles”)
公共类角色2{
/**
*具有所有属性的角色模型
*/
私人长id;
私有集合名;
公共角色2(){
}
公共角色2(集合名称){
this.name=名称;
}
@身份证
@GeneratedValue(策略=GenerationType.IDENTITY)
公共长getId(){
返回id;
}
公共无效集合id(长id){
this.id=id;
}
@独身癖
公共集getName(){
返回名称;
}
公共无效集合名(集合名){
this.name=名称;
}
}

我已经讨论了几个小时了,但我没有真正理解原因。如果有人能在这里指出这个问题,我将不胜感激。提前感谢

为什么您使用了
私有集名称
而不是
私有字符串名称
Role2
中的内部
@OneToMany
关系对我来说没有意义。另一方面,
User2
中的
@manytone
Role2
的定义错误。有关如何以合适的方式开发Hibernate关联的更多信息,请参阅:
@Entity
@Table(name = "users")
public class User2 {
    /**
     * User model
     */ 
        
      private long id;    
      private String username;   
      private String email;   
      private String password;
      private String customername;    
      private String customerid;      
      private String description;      
     

      private Set<Role2> roles = new HashSet<>();

      public User2() {
      }

      public User2(String username, String email, String customername,String customerid,String description, String password) {
        this.username = username;
        this.email = email;
        this.customername = customername;
        this.customerid = customerid;
        this.description = description;
        this.password = password;
      } 
      

      @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
            public long getId() {
            return id;
        }

      public void setId(long id) {
        this.id = id;
      }
      
      @Column(name = "username", nullable = false, length = 1024)
      public String getUsername() {
        return username;
      }

      public void setUsername(String username) {
        this.username = username;
      }

      @Column(name = "email", nullable = false, length = 1024)
      public String getEmail() {
        return email;
      }

      public void setEmail(String email) {
        this.email = email;
      }

      @Column(name = "password", nullable = false, length = 1024)
      public String getPassword() {
        return password;
      }

      public void setPassword(String password) {
        this.password = password;
      }

     
      @Column(name = "customername", nullable = false, length = 1024)
      public String getCustomername() {
        return customername;
    }

    
    public void setCustomername(String customername) {
        this.customername = customername;
    }

    @Column(name = "customerid", nullable = false, length = 1024)
    public String getCustomerid() {
        return customerid;
    }
    
    
    public void setCustomerid(String customerid) {
        this.customerid = customerid;
    }

    @Column(name = "description", nullable = false, length = 1024)
    public String getDescription() {
        return description;
    }
    
    
    public void setDescription(String description) {
        this.description = description;
    }
    
    
    @ManyToOne(targetEntity = Role2.class)
    @JoinColumn(name = "role")
    public Set<Role2> getRoles() {
        return roles;
      }
    
    public void setRoles(Set<Role2> roles) {
        this.roles = roles;
    }
    
    


    }
@Entity
@Table(name = "roles")
public class Role2 {
    /**
     * Model for role with all the attributes
     */
     
      private long id;

     
      private Set<Role2> name;

      public Role2() {

      }

      public Role2(Set<Role2> name) {
        this.name = name;
      }

      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      public long getId() {
        return id;
      }

      public void setId(long id) {
        this.id = id;
      }
      
      @OneToMany
      public Set<Role2> getName() {
        return name;
      }

      public void setName(Set<Role2> name) {
        this.name = name;
      }
    }