问题描述
首先发布到stackoverflow,所以请原谅,如果我没有正确发布。我在旧线索上发布了带有代码的后续问题的联结表中的值,因为我无法获得推荐的解决方案以正常运行。我正在使用OpenXava并收到错误无法执行保存操作:org.hibernate.PropertyAccessException:无法通过org.openxava.invoicing.model.CourseAssignmentId.course的反射设置器设置字段值。任何帮助表示赞赏。我的代码:用户类:
@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)
私人收藏< CourseAssignment> courseAssignments;
public Collection< CourseAssignment> getcourseAssignments(){
return courseAssignments;
}
public void setcourseAssignments(Collection< CourseAssignment> courseAssignments){
this.courseAssignments = courseAssignments;
}
}
课程分类:
@Entity
@Table(name =courses)
public class Course {
@Id
@Column(name =pk1)
私有长ID;
public Long getid(){
return id;
}
public void setid(Long id){
this.id = id;
}
@Column(name =course_name)
私人字符串名称;
public String getname(){
return name;
}
public void setname(String name){
this.name = name;
}
@OneToMany(mappedBy =course)
私人收藏< CourseAssignment> courseAssignments;
public Collection< CourseAssignment> getcourseAssignments(){
return courseAssignments;
}
public void setcourseAssignments(Collection< CourseAssignment> courseAssignments){
this.courseAssignments = courseAssignments;
}
}
CourseAssignment类:
@Entity
@Table(name =course_users)
@IdClass(CourseAssignmentId.class)
public class CourseAssignment {
@Id
@ManyToOne
@JoinColumn(name =user_pk1)
私人用户用户;
public User getuser(){
return user;
}
public void setuser(User user){
this.user = user;
@Id
@ManyToOne
@JoinColumn(name =crsmain_pk1)
私人课程;
公开课程getcourse(){
return course;
}
public void setcourse(Course course){
this.course = course;
@Column(name =role)
私人字符串角色;
public String getrole(){
return role;
}
public void setrole(String role){
this.role = role;
CourseAssignmentId类:
@Embeddable
public class CourseAssignmentId implements java.io.Serializable {
private static final long serialVersionUID = 1L;
@Column(name =user_pk1)
私人长用户;
public long getuser(){
return user;
}
public void setuser(长用户){
this.user = user;
}
@Column(name =crsmain_pk1)
私人长课程;
public Long getcourse(){
return course;
}
public void setcourse(Long course){
this.course = course;
}
}
事情要尝试:
@Column
来自 CourseAssignmentId
equals()
和 code> CourseAssignmentId
中的hashCode()
First post to stackoverflow, so please excuse if I did not post correctly. 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". 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:
@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:
@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 fromCourseAssignmentId
(I don't think it is appropriate in this context) - Removing the
@Column
annotations fromCourseAssignmentId
- Implementing
equals()
andhashCode()
inCourseAssignmentId
这篇关于在连接表中映射值& hibernate.PropertyAccessException:无法通过反射设置器设置字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!