简体   繁体   English

在连接表和hibernate.PropertyAccessException中映射值:无法通过反射设置器设置字段值

[英]Mapping Value in Junction Table & hibernate.PropertyAccessException: could not set a field value by reflection setter

First post to stackoverflow, so please excuse if I did not post correctly. 首先发布到stackoverflow,所以如果我没有正确发布,请原谅。 I posted a follow-up question with code on an old thread Mapping value in junction table to Entity as I am not able to get the recommended solution to function properly. 我发布了一个后续问题,其中包含旧线程上的代码将联结表中的映射值映射到实体,因为我无法获得推荐的解决方案以正常运行。 I am using OpenXava and receive error "Impossible to execute Save action: org.hibernate.PropertyAccessException: could not set a field value by reflection setter of org.openxava.invoicing.model.CourseAssignmentId.course". 我正在使用OpenXava并收到错误“无法执行保存操作:org.hibernate.PropertyAccessException:无法通过org.openxava.invoicing.model.CourseAssignmentId.course的反射设置器设置字段值”。 Any help is appreciated. 任何帮助表示赞赏。 My code: 我的代码:

User Class: 用户类:

@Entity
@Table(name="users")
public class User {
    @Id
    @Column(name="pk1")
    private Long id;

    public Long getid() {
        return id;
    }

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

    @Column(name="user_id")
    private String userID;

    public String getuserID(){
        return userID;
    }

    public void setuserID(String userID) {
        this.userID = userID;
    }

    @OneToMany(mappedBy="user")
    private Collection<CourseAssignment> courseAssignments;

    public Collection<CourseAssignment> getcourseAssignments() {
        return courseAssignments;
    }

    public void setcourseAssignments(Collection<CourseAssignment> courseAssignments) {
        this.courseAssignments = courseAssignments;
    }

}

Course Class: 课程班级:

@Entity
@Table(name="courses")
public class Course {

    @Id
    @Column(name="pk1")
    private Long id;

    public Long getid() {
        return id;
    }

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

    @Column(name="course_name")
    private String name;

    public String getname() {
        return name;
    }

    public void setname(String name) {
        this.name = name;
    }   

    @OneToMany(mappedBy = "course")
    private Collection<CourseAssignment> courseAssignments;

    public Collection<CourseAssignment> getcourseAssignments() {
        return courseAssignments;
    }

    public void setcourseAssignments(Collection<CourseAssignment> courseAssignments) {
        this.courseAssignments = courseAssignments;
    }


}

CourseAssignment Class: CourseAssignment类:

@Entity
@Table(name="course_users")
@IdClass(CourseAssignmentId.class)
public class CourseAssignment {

    @Id
    @ManyToOne
    @JoinColumn(name="user_pk1")
    private User user;

    public User getuser() {
        return user;
    }

    public void setuser(User user) {
        this.user = user;
    }

    @Id
    @ManyToOne
    @JoinColumn(name="crsmain_pk1")
    private Course course;

    public Course getcourse() {
        return course;
    }

    public void setcourse(Course course) {
        this.course = course;
    }

    @Column(name="role")
    private String role;

    public String getrole() {
        return role;
    }

    public void setrole(String role) {
        this.role = role;
    }
}

CourseAssignmentId Class: CourseAssignmentId类:

@Embeddable
public class CourseAssignmentId implements java.io.Serializable {

    private static final long serialVersionUID = 1L;


    @Column(name="user_pk1")
    private Long user;

    public Long getuser() {
        return user;
    }

    public void setuser(Long user) {
        this.user = user;
    }

    @Column(name="crsmain_pk1")
    private Long course;

    public Long getcourse() {
        return course;
    }

    public void setcourse(Long course) {
        this.course = course;
    }   
}

Some things to try: 有些事要尝试:

  • Removing the @Embeddable annotation from CourseAssignmentId (I don't think it is appropriate in this context) CourseAssignmentId删除@Embeddable注释(我不认为它在这种情况下是合适的)
  • Removing the @Column annotations from CourseAssignmentId CourseAssignmentId删除@Column注释
  • Implementing equals() and hashCode() in CourseAssignmentId CourseAssignmentId实现equals()hashCode()

暂无
暂无

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

相关问题 如何修复org.hibernate.PropertyAccessException:无法通过反射设置器设置字段值 - How to fix org.hibernate.PropertyAccessException: Could not set field value value by reflection setter of 使用ManyToOne获取org.hibernate.PropertyAccessException的JPA Composite键:无法通过反射设置器设置字段值 - JPA Composite key with ManyToOne getting org.hibernate.PropertyAccessException: could not set a field value by reflection setter of Hibernate &amp; Spring - org.hibernate.PropertyAccessException: 无法通过反射设置字段值 [1] 值 - Hibernate & Spring - org.hibernate.PropertyAccessException: Could not set field value [1] value by reflection org.hibernate.PropertyAccessException: 无法通过反射为 String 设置字段值 [STRING] 值 - org.hibernate.PropertyAccessException: Could not set field value [STRING] value by reflection for String PropertyAccessException:使用Hibernate时无法通过反射getter获取字段值 - PropertyAccessException: could not get a field value by reflection getter While using Hibernate org.hibernate.PropertyAccessException:无法通过反射getter获取字段值 - org.hibernate.PropertyAccessException: could not get a field value by reflection getter of Hibernate / JPA:无法通过反射设置器设置字段值 - Hibernate/JPA: could not set a field value by reflection setter PropertyAccessException:无法通过反射获取器获取字段值 - PropertyAccessException: could not get a field value by reflection getter org.hibernate.PropertyAccessException:无法使用复合键设置字段值 - org.hibernate.PropertyAccessException: Could not set field value with Composite Key 嵌套的异常是org.hibernate.PropertyAccessException:无法设置字段值 - nested exception is org.hibernate.PropertyAccessException: Could not set field value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM