Spring JPA OneToMany儿童
我用Spring Boot JPA,如何坚持孩子与一夫一妻的关系? 在创建父实体时,子实体似乎不会自动持久化 其他人的关系很好,为什么 注册实体:Spring JPA OneToMany儿童,spring,jpa,spring-boot,Spring,Jpa,Spring Boot,我用Spring Boot JPA,如何坚持孩子与一夫一妻的关系? 在创建父实体时,子实体似乎不会自动持久化 其他人的关系很好,为什么 注册实体: @Entity @Table(name="Registration") public class Registration implements Serializable { @Id @GeneratedValue(generator = "uuid") @GenericGenerator(name="uuid", strat
@Entity
@Table(name="Registration")
public class Registration implements Serializable {
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name="uuid", strategy = "uuid2")
@Column(columnDefinition = "BINARY(16)")
private UUID uuid;
@OneToMany(mappedBy ="registration", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name="registration", nullable = false)
private List<Payment> payment;
private DateTime created;
private DateTime updated;
}
尝试创建注册时记录:
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:列“created”不能为null
不清楚它抱怨哪个“创建”列为空。您在注册和付款中都有“已创建”的财产。在任何一种情况下,如果您的数据库表不接受空值,则该列似乎没有被设置在某个位置null@Mezoo看起来您是从一些JSON内容填充实体。您需要为子项的
created
字段设置一些值,或者使Payment
表允许created
列为空值。
@Entity
@Table(name="Payment")
public class Payment {
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name="uuid", strategy = "uuid2")
@Column(columnDefinition = "BINARY(16)")
private UUID uuid;
/* @ManyToOne(targetEntity=Registration.class)
@JoinColumn(name="registration")
private Registration registration; */
private DateTime created;
private DateTime updated;
}