Hi below is my entities with manytoone association between them
student.java
@Entity
@Table(name = "student")
public class student{
@Id
@Column(name = "UserID")
private String userid;
@ManyToOne(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "userrole", referencedColumnName = "VALUE"),
@JoinColumn(name = "userrole", referencedColumnName = "DESCRIPTION")
})
private studentdetails userrole;
//setters and getters
//constructor
}
studentdetails.java
@Data
@Entity
@Table(name = "student_details")
public class studentdetails {
@Id
@Column(name = "VALUE")
private String value;
@Id
@Column(name = "DESCRIPTION")
private String description;
//setters and getters
//constructor
}
appmain.java
public static void main()
{
//session configuration
studentdetails sd = new studentdetails();
sd.setvalue("abc");
sd.setdescription("abcdef");
student student1 = new student();
student.setuserid("1");
student.userrole(sd);
student student2 = new student();
student.setuserid("2");
student.userrole(sd);
session.save(student1 );
session.save(student2 );
}
below are the columns in my 2 table
student:
UserID
userrole
student_details:
VALUE
DESCRIPTION
the "value" in "student_details" should enter into "userrole" of student table
but when I execute my appmain I am getting below error
org.hibernate.MappingException: Foreign key (FK6D56043A4415BDB5:student [userrole])) must have same number of columns as the referenced primary key (student_details [VALUE,DESCRIPTION])
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:113)
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:96)
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1354)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1261)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:383)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1377)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954)
I tried to solve this but it showing same error please suggest me how to solve this