【发布时间】:2015-10-30 18:53:03
【问题描述】:
我正在尝试使用 Dozer 从 JAXB 实体“JaxbParent”填充 Hibernate 实体 -“Parent”。 我的休眠实体:
public class Parent
{
String name;
String age;
@OneToMany
private Set<Child> childSet;
}
public class Child
{
String name;
String age;
@ManyToOne
private Parent parent;
}
我的 Jaxb 实体如下所示:
public class JaxbParent
{
List<JaxbChild> childList;
}
我的推土机 xml 映射配置:
<mapping wildcard="false">
<class-a>com.test.Parent</class-a>
<class-b>com.test.JaxbParent</class-b>
<field custom-converter="com.test.MyCustomConverter">
<a>childSet</a>
<b>childList</b>
</field>
</mapping>
所以,为了将 childList 转换为 childSet,我使用了 CustomConverter,并且我得到了正确的数据字段。 问题是,Hibernate 需要每个 Child 都引用 Parent 对象(以执行保存),但目前它为 null。我尝试将“this”引用传递给 MyCustomConverter,但这没有成功。 如何将 Parent 对象的引用传递给 customConverter,传递给每个 Child 对象?也许我应该使用另一种方法?任何帮助表示赞赏。
【问题讨论】: