I have a relationship like

<set name="someBeans" table="sometable" cascade="all, delete-orphan" inverse="true" lazy="true">
        <key column="some_id" />
        <one-to-many class="someBean" />
    </set>

in my Java code there was a set performed on this which was like

myClass.setSomeBeans(SomeBeans); 

now this SomeBeans is a linkedHashmap and so the order was maintained, however because of all Delete Orphan being used in cascade i was getting exception in a particular scenario as :

HibernateException – A collection with cascade=”all-delete-orphan” was no longer referenced by the owning entity instance

So i changed the java implementation above to

myClass.getSomeBeans().clear();
myClass.getSomeBeans().addAll(SomeBeans)

However doing this i am not able to sustain the order from linkedHashMap SomeBeans.

Has anyone faced such issue as well, any help in this regard would be appriciated

Regards,

Vaibhav

有帮助吗?

解决方案

Just to accomplish what i wanted to i created a dummy object copied the properties from the hibernate Object and applied the sorting on it, which got preserved and all delete orphan related problem was also taken care of.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top