我正在尝试创建一个“简单”的一个或多个或多个的关系。我得到以下例外情况:
有人能告诉我我做错了什么吗?
下面你可以找到我的两个实体。
提前谢谢你。
import javax.persistence.OneToMany;
@Entity
@Table(uniqueConstraints={@UniqueConstraint(columnNames={"questionGroupID","questionID"})})
public class QuestionGroupEntity implements Serializable{
private static final long serialVersionUID = 1796640204447018439L;
@Id
@NotEmpty
@Column(name="question_group_id")
private String questionGroupID;
@NotEmpty
private String label;
@NotEmpty
private String questionID;
@OneToMany(fetch=FetchType.EAGER,targetEntity=QuestionGroupMappingEntity.class,mappedBy="questionGroup")
List<QuestionGroupMappingEntity> questionGroupMappings;
而且
import javax.persistence.ManyToOne;
@Entity
@Table(uniqueConstraints={@UniqueConstraint(columnNames={"questionGroupID","questionID","answerID"})})
public class QuestionGroupMappingEntity implements Serializable {
private static final long serialVersionUID = 8437546139229082305L;
@Id
@SequenceGenerator(name="groupMappingIDGenerator")
@GeneratedValue(generator="groupMappingIDGenerator",strategy=GenerationType.AUTO)
private String groupMappingID;
@NotEmpty
private String questionID;
@NotEmpty
private String questionGroupID;
@NotEmpty
private String answerID;
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="question_group_id")
private QuestionGroupEntity questionGroup;
谢谢你的回答。我通过添加spring.jpa.hibernate.ddl-auto=update spring.jpa.generate-ddl=true属性解决了这个问题。问题是spring-data无法更新模式。