Note that there are some explanatory texts on larger screens.

plurals
  1. POMapping ManyToMany with composite Primary key and Annotation:
    primarykey
    data
    text
    <p>I'm trying to create manytomany realation between Student and Teaching Course using Composite Primary key:</p> <p>my classes:</p> <pre><code>@Entity @Table(name="Student_mtm_cId") public class Student { private String id; private Set&lt;StudentTClass&gt; teachingClasses = new HashSet&lt;StudentTClass&gt;(); @OneToMany(fetch = FetchType.LAZY, mappedBy = "pk.student") public Set&lt;StudentTClass&gt; getTeachingClasses() { return teachingClasses; } public void setTeachingClasses(Set&lt;StudentTClass&gt; teachingClasses) { this.teachingClasses = teachingClasses; } public void addStudentToClass(TeachingClass teachingClass){ StudentTClass studentTClass = new StudentTClass(); studentTClass.setStudent(this); studentTClass.setTeachingClass(teachingClass); teachingClasses.add(studentTClass); } public void setLastName(String lastName) { this.lastName = lastName; } @Id @GeneratedValue(generator="system-uuid") @GenericGenerator(name="system-uuid", strategy = "uuid") @Column(name = "student_id", nullable = false) public String getId() { return id; } public void setId(String id) { this.id = id; } //all other setters and getters and isequal/hashCode omitted. } </code></pre> <p>TeachingClass:</p> <pre><code>@Entity @Table(name="TechingClass_MTM") public class TeachingClass { private String id; private String name; private String description; private Set&lt;StudentTClass&gt; teachingClasses = new HashSet&lt;StudentTClass&gt;(); public TeachingClass(){} public TeachingClass(String name, String description) { super(); this.name = name; this.description = description; } public void addStudentToClass(Student student){ StudentTClass studentTClass = new StudentTClass(); studentTClass.setStudent(student); studentTClass.setTeachingClass(this); teachingClasses.add(studentTClass); } @OneToMany(fetch = FetchType.LAZY, mappedBy = "pk.teachingClass") public Set&lt;StudentTClass&gt; getTeachingClasses() { return teachingClasses; } public void setTeachingClasses(Set&lt;StudentTClass&gt; teachingClasses) { this.teachingClasses = teachingClasses; } public void setDescription(String description) { this.description = description; } @Id @GeneratedValue(generator="system-uuid") @GenericGenerator(name="system-uuid", strategy = "uuid") @Column(name = "teachingClass_id", nullable = false) public String getId() { return id; } public void setId(String id) { this.id = id; } } </code></pre> <p>Collection Objects:</p> <pre><code>@Entity @Table(name = "student_TClass_MTM") @AssociationOverrides({ @AssociationOverride(name = "pk.student", joinColumns = @JoinColumn(name = "student_id")), @AssociationOverride(name = "pk.teachingClass", joinColumns = @JoinColumn(name = "teachingClass_id")) }) public class StudentTClass { @EmbeddedId private StudentTClassPK pk = new StudentTClassPK(); public StudentTClassPK getPk() { return pk; } public void setPk(StudentTClassPK pk) { this.pk = pk; } public StudentTClass() {} @Transient public Student getStudent(){ return this.pk.getStudent(); } @Transient public TeachingClass getTeachingClass(){ return this.pk.getTeachingClass(); } public void setStudent(Student student){ this.pk.setStudent(student); } public void setTeachingClass(TeachingClass teachingClass){ this.pk.setTeachingClass(teachingClass); } } </code></pre> <p>Now The primary Key:</p> <pre><code>@Embeddable public class StudentTClassPK implements Serializable{ private static final long serialVersionUID = -7261887879839337877L; private Student student; private TeachingClass teachingClass; @ManyToOne public Student getStudent() { return student; } public void setStudent(Student student) { this.student = student; } @ManyToOne public TeachingClass getTeachingClass() { return teachingClass; } public void setTeachingClass(TeachingClass teachingClass) { this.teachingClass = teachingClass; } public StudentTClassPK(Student student, TeachingClass teachingClass) { this.student = student; this.teachingClass = teachingClass; } public StudentTClassPK() {} } </code></pre> <p>When I'm trying to Persist Student I got the following error:</p> <pre><code>Caused by: org.hibernate.MappingException: Could not determine type for: com.vanilla.objects.Student, at table: student_TClass_MTM, for columns: [org.hibernate.mapping.Column(student)] at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:306) at org.hibernate.tuple.PropertyFactory.buildStandardProperty(PropertyFactory.java:143) at org.hibernate.tuple.component.ComponentMetamodel.&lt;init&gt;(ComponentMetamodel.java:68) at org.hibernate.mapping.Component.buildType(Component.java:184) at org.hibernate.mapping.Component.getType(Component.java:177) at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:290) at org.hibernate.mapping.RootClass.validate(RootClass.java:236) at org.hibernate.cfg.Configuration.validate(Configuration.java:1362) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1865) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:855) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:774) at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417) ... 51 more </code></pre> <p>What am I doing wrong? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload