开发者

Hibernate - Setting a cascade persist just for one session

I have this relation in Hibernate:

    n      1
A   ------->   B

The cascade types in the @OneToMany from A to B is not CascadeType.PERSIST, and cannot be made so. The @ManyToOne from B to A doesn't have CascadeType.PERSIST either.

Now I have the case where I have a new unpersisted A referring a new unpersisted B which refers to the unpersisted A.

Persisting A l开发者_运维问答eads to the exception, that A referes to the "null or transient instance" B, of course. Persisting B beforehand leads to the same error, because A is not persisted.

How do I solve this? Can I specify a one-time-Cascade-persist?


If you don't have any cascading set up on the one-to-many part, the only way I can think of is to create and persist A first.. and then you can create and add Bs into the persisted A.

Any particular reason why you do not want to set up the cascade in this bidirectional relationship?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜