Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java hibernate中是否存在多级结构_Java_Spring_Spring Boot_Hibernate_Spring Mvc - Fatal编程技术网

Java hibernate中是否存在多级结构

Java hibernate中是否存在多级结构,java,spring,spring-boot,hibernate,spring-mvc,Java,Spring,Spring Boot,Hibernate,Spring Mvc,如果我要问有子问题的问题,并且所有问题和子问题都有各自的答案,那么如何设计bean的以下结构。结构就像 如何在hibernate中设计此结构以实现spring boot中的功能。如果我们考虑到这是3个不同的表,我会认为这是一个问题的实体 @Entity @Table("question") public class Question @Entity @Table("sub_question") public class SubQuestion 然后是

如果我要问有子问题的问题,并且所有问题和子问题都有各自的答案,那么如何设计bean的以下结构。结构就像


如何在hibernate中设计此结构以实现spring boot中的功能。

如果我们考虑到这是3个不同的表,我会认为这是一个问题的实体

@Entity
@Table("question")
public class Question
@Entity
@Table("sub_question")
public class SubQuestion
然后是
子问题的实体

@Entity
@Table("question")
public class Question
@Entity
@Table("sub_question")
public class SubQuestion
manytone
association

  @ManyToOne(fetch=FetchType.LAZY)
  @JoinColumn(name="QUESTION_ID")
  private Question question;
最后是泛型类
GenericAnswer

@Entity
@Table(name = "answer")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "question", discriminatorType = DiscriminatorType.STRING)
public class GenericAnswer {
它将扩展为两个类,
问题答案
子问题答案

@Entity
@Table(name = "answer")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "question", discriminatorType = DiscriminatorType.STRING)
public class GenericAnswer {
这两个类有一个鉴别器列来区分它们所引用的表(问题或子问题)


希望这对您有所帮助。

如果子问题是某些问题的可选字段,那么会出现什么情况?