【发布时间】:2023-03-14 23:25:01
【问题描述】:
我有一个父表和一个子表,其中父表和子表之间存在一对多的关系 - 在尝试保存也应该保存子数据的父数据时,我遇到了一个异常 - java.sql。 SQLSyntaxErrorException:ORA-00932:不一致的数据类型:预期的 DATE 得到了 BINARY
这是我的代码:
@Entity(name ="Parent")
public class Parent {
@Id
@Generate.....
@Column
private int id;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "parent")
private List<Child> children = new ArrayList<Child>();
simple ... getter and setter ...
}
@Entity(name ="Child")
public class Child{
@EmbeddedId
@Column(name = "ID")
private ChildCompositeIds id;
... simple getter an setter
}
@Embeddable
public class ChildCompositeIds implements Serializable {
@Column(name = "child_name")
private String childName;
@Column(name = "birth_date",columnDefinition = "DATE")
private LocalDate birthDate;
public ChildCompositeIds () {
}
public ChildCompositeIds (String childName, LocalDate birthDate) {
this.childName= childName;
this.birthDate= birthDate;
}
simple ... getter and setter ...
}
在保存父数据时,我可以看到“ChildCompositeIds”类中的所有子数据都已正确填充,但我仍然收到此异常 - java.sql.SQLSyntaxErrorException:ORA-00932:不一致的数据类型:预期DATE 得到 BINARY。 这与“birthDate”字段有关,因为我怀疑作为主键之一的生日值以某种方式变为 null 但不知道为什么 - 请协助
【问题讨论】:
-
Remvoe @Column(name = "ID") 以及出生日期的列定义
标签: spring hibernate jpa spring-data-jpa one-to-many