sql查询填充包含字符串列表的类对象

时间:2017-06-22 17:07:32

标签: java sql hibernate jpa spring-boot

我正在创建一个调查项目,Survey有一些选择题。对于调查和问题,我有一个班级,

@Entity
public class SurveyEntity {
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private String surveyId;
    private String title;
    private String description;
    private List<QuestionEntity> questions; 
}


@Entity
public class QuestionEntity {
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private String questionId;
    private String description;
    private String correctAns;
    private List<String> options;
}

我想在项目启动时预先填充数据。所以我写了一个sql文件(initial.sql)并将其放入Spring Boot的application.properties

insert into SurveyEntity(surveyId, title, description) values("Survey1", "Collected Survey", "description of the survey1");

insert into QuestionEntity(questionId, description, correctAns, ?) values ("Question1", "Largest Country in the World", "Russia", ??);
insert into QuestionEntity(questionId, description, correctAns, ?) values ("Question2", "Most populous Country in the World", "China", ??);
insert into QuestionEntity(questionId, description, correctAns, ?) values ("Question3", "Highest GDP in the World", "United States", ??);
insert into QuestionEntity(questionId, description, correctAns, ?) values ("Question4", "Second largest English speaking country", "India", ??);

我的问题是,如何使用上述语句填充字符串列表(options已提交)?或者我是否需要为options创建一个单独的表?

0 个答案:

没有答案