Java – Hibernate: how to use cascading in annotations?
•
Java
How to use cascading and annotation in Hibernate?
But I 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 session An error occurs when saving a package I don't want to save products and packages, just initialize them and set them as my package objects
Is that possible?
Solution
The problem of Hibernate documentation is very clear For example, you can use,
@Cascade(CascadeType.PERSIST) private List<Object> obj;
or
@OneToMany(cascade = CascadeType.PERSIST) private List<Object> obj;
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码