Note that there are some explanatory texts on larger screens.

plurals
  1. POusing hibernate to generate one to many relation through annotation
    primarykey
    data
    text
    <p>I am just a beginner in learning Spring MVC and Hibernate technologies. I am trying to use hibernate to access my database and I am using annotation method to configuring my beans to database. I am trying to make a one to many relation which is throwing me error. </p> <p>Basically I am it is a "one use can post multiple quiz" relation</p> <p>the error while configuring hibernate is :<br/> <strong>org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: bean.User.quizPosted[bean.Quiz] Use of @OneToMany or @ManyToMany targeting an unmapped class: bean.User.quizPosted[bean.Quiz]</strong></p> <p>my code for the two beans are : </p> <p>User.java</p> <pre><code> package bean; import java.util.HashSet; import java.util.Set; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.persistence.UniqueConstraint; @Entity @Table(name="User", uniqueConstraints ={@UniqueConstraint(columnNames="userName"})}) public class User { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id; @ManyToOne(targetEntity=Person.class) @JoinColumn(name="PersonId") private Person person; @Column(name="userName") private String userName; @Column(name="password") private String password; @Column(name="role") private String role; @OneToMany(mappedBy = "postedBy") private Set&lt;Quiz&gt; quizPosted = new HashSet&lt;Quiz&gt;(); @OneToMany(mappedBy = "userId") private Set&lt;User_Quiz&gt; user_Quizs = new HashSet&lt;User_Quiz&gt;(); } </code></pre> <p>and quiz.java</p> <pre><code> package bean; import java.sql.Date; import java.util.HashSet; import java.util.Set; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.persistence.UniqueConstraint; @Entity @Table(name = "Quiz") public class Quiz { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer quizId; @Column(name = "duration") private Integer duration; @Column(name = "date") private Date date; @ManyToOne(targetEntity = User.class) @JoinColumn(name = "postedBy") private User postedBy; @OneToMany(mappedBy="quizId") private Set&lt;User_Quiz&gt; user_Quizs = new HashSet&lt;User_Quiz&gt;(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
    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