Как установить доменное поле в виде списка номеров

0

Я хочу определить одно поле в таблице 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)]

Я также попробовал Set, но не работал. Может ли кто-нибудь помочь мне в этом?

  • 0
    Не могли бы вы попытаться @Column аннотацию @Column для questionAns?
  • 0
    Я понял, что вам может понадобиться создать an entity for questionAns которая содержит Long , и определить отношение one-to-many relation с помощью QuestionResponse .
Показать ещё 1 комментарий
Теги:
spring-boot
hibernate
jpa

1 ответ

0

вы можете использовать это:

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;




   }

Ещё вопросы

Сообщество Overcoder
Наверх
Меню