我正在尝试保存嵌套对象,而我不想保存一个对象。我怎样才能做到这一点?当我运行这个时,我得到了短暂的异常
org.hibernate.TransientObjectException: object references an unsaved transient instance.
我知道我在做一些hibernate不推荐的愚蠢的事情。
设想:
A, B, C, D are four different tables.
Table A ( field1, field2 , field3[fk to table B])
Table B ( field3, field4 , field5 [fk to table C])
Table C ( field5, field7 , field8)
Table D ( field6, field9 , field3[fk to table B])
对象
一个
private String field1;
private String field2;
@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name="field3")
private B b;
乙
private String field3;
private String field4;
//Want to save D
@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name="field3")
private List<D> d; // This is a list of D
//Dont want to save C
@OneToOne
@JoinColumn(name="field5")
private C c;
C
private String field5;
private String field7;
private String field8;
D
private String field6;
private String field9;
private String field3;