java—如何将域字段设置为数字列表

h5qlskok  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(254)

我想在question\u response表中定义一个字段作为数字列表。

@Entity
public class QuestionResponse {
  @Id
  @GeneratedValue(strategy= GenerationType.AUTO)
  @Column(name="question_response_id", nullable = false, updatable = false)
  private Long question_response_id;

  @ManyToOne(fetch = FetchType.EAGER)
  @JoinColumn(name = "user_uuid")
  private User users;

  @ManyToOne(fetch = FetchType.EAGER)
  @JoinColumn(name = "question_id")
  private Question questions;

  private List<Long> questionAns;
}

但它给出了一个错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: question_response, for columns: [org.hibernate.mapping.Column(question_ans)]

我也试过set,但没用。有人能帮我吗?

xdyibdwo

xdyibdwo1#

您可以使用:

public class Answer{
 @Column(name="id_response")
 private long Idresponse;
 @Column(name="response") 
 private String response;

@JsonIgnore  
@ManyToOne
@JoinColumn(name="question")
private QuestionResponse questionResponse;

 }

然后在questionresponse类中,您可以使用如图所示的一个omany关系,它将起作用:

@Entity
   public class QuestionResponse {
   @Id
   @GeneratedValue(strategy= GenerationType.AUTO)
   @Column(name="question_response_id", nullable = false, updatable = false)
   private Long question_response_id;

   @ManyToOne(fetch = FetchType.EAGER)
   @JoinColumn(name = "user_uuid")
   private User users;

   @ManyToOne(fetch = FetchType.EAGER)
   @JoinColumn(name = "question_id")
   private Question questions;

   @OneToMany(mappedBy = "answer", cascade = CascadeType.ALL)  
   private Set<Answer> answer;

   }

相关问题