Hibernate:如何在注释中使用级联? [英] Hibernate: How use cascade in annotation?
本文介绍了Hibernate:如何在注释中使用级联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何在hibernate中使用级联和批注?
但我仍然怀疑:
我有这种情况:
$ b $ pre $ public class Package(){
@OneToOne(cascade = CascadeType.PERSIST)
私人产品;
@OneToOne(cascade = CascadeType.PERSIST)
私人用户用户;
..
}
当我尝试 session.save(包)
,发生错误。
我不想保存产品和包,只需初始化然后将它们设置到我的包对象中即可。
这可能吗?
解决方案
请参阅 hibernate documentation ,这个问题非常明确。例如,您可以使用例如
@Cascade(CascadeType.PERSIST)
private List< Object> OBJ;
或
@OneToMany(cascade = CascadeType.PERSIST)
private List< Object> OBJ;
How can I use cascade and annotations in hibernate ?
But I stay with a doubt:
I have this situation:
public class Package(){
@OneToOne(cascade=CascadeType.PERSIST)
private Product product;
@OneToOne(cascade=CascadeType.PERSIST)
private User user;
..
}
When I try to session.save(package)
, an error occurs.
I don't want to save product and package, just initialize then and set them into my package object.
Is that possible ?
解决方案
See the hibernate documentation which is very clear on this issue. For instance you could use e.g.,
@Cascade(CascadeType.PERSIST)
private List<Object> obj;
or
@OneToMany(cascade = CascadeType.PERSIST)
private List<Object> obj;
这篇关于Hibernate:如何在注释中使用级联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文