| I've just looked in the source code and found that adding constraint=true causes the one-to-one foreign key direction changing from TO_PARENT to FROM_PARENT (in ModelBinder). Therefore the association saving is cascaded before the root entity is saved then root id null. Here are my solutions:- 1. Separating properties for read and write so the read property can be lazily loaded (with batch) and the write property make the first save work. This requires no hibernate's code change at all but a bit funny. 2. The second solution needs code change and more attribute for the one-to-one association type. The attribute "foreign-key-type" should be available for change so we can use constraint=true and set foreign-key-type=TO_PARENT. The code change should be done in ModelBinder#bindOneToOne() . I am using the first solution in my project for now. |