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

标签 java mysql hibernate spring-boot jpa

我想将 Question_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)]

我也尝试过设置,但没有成功。有人可以帮我解决这个问题吗?

最佳答案

你可以使用这个:

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 类中,您可以使用 OneToMany 关系,如图所示,它将起作用:

   @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;




   }

关于java - 如何将域字段设置为数字列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52347982/

相关文章:

java - 将 Unix 日期从 php 转换为 Java (Android)

php - laravel - 三个表的内连接查询

java - 是否可以为多个列创建一个索引? hibernate

java - 将日期转换为文本格式

Java时区搞砸了

java - 如何在eclipse上安装maven

Java + Spring + Hibernate : "order by" slow on production

mysql - 三重嵌套 mysql select 在应该返回结果时没有返回结果

php - 自注册之日起两周后发送电子邮件

java - Spring JPA 优化传递@ManyToOne 获取