I am new with JPA. I am building sample maven project with Wicket-Spring-Hibernate-JPA.
I am using Hibernate EntityManager: v4.3.5.Final. I am using JPA: v2.1-api. I am using database mySql: v5.6.
When I am writing a model class, I want to map tables multiple columns with an element in model class as List or Set.
Database Table Name: QUESTION_MAIN
Column Name : Type : PK
QID : int : PK
QTYPE : varchar
QUESTION : varchar
OPTION1 : varchar
OPTION2 : varchar
OPTION3 : varchar
OPTION4 : varchar
OPTION5 : varchar
OPTION6 : varchar
Note: Assuming that there will be maximum 6 options to question.
Now in model class, I want to represent this like:
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="QUESTION_MAIN")
public class Question {
@Id
@GeneratedValue
@Column(name="QID")
private Long id;
@Column(name="QTYPE")
private String quest_type;
@Column(name="QUESTION")
private String question;
//TODO: Create List or Set for OPTIONS
}
For the line in code:
//TODO: Create List or Set for OPTIONS
I want to create a List or Set for the options columns here.
Please do let me know any possible way for this. Or if anyone aware of such situation, provide any alternative to this.
Hello Luiggi, I am not sure the above link you provided solves my issue. Still I am trying to understand the option provided in that link. What I am looking for is, can I be able to create a List or Set of ColumnNames as one element in our Bean Class (with JPA Annotations).