Yes, I have both sides mapped, since they are the same class.
Here is my complete mapping:
Code:
<hibernate-mapping>
<class name="eg.Entity" table="entity">
<id name="id" column="id" length="30" type="string">
<generator class="assigned"/>
</id>
<property name="name" column="name" type="string" length="40" not-null="true"/>
<property name="parentId" column="parent_id" type="string" length="30"/>
<many-to-one name="parent" class="eg.Entity" column="parent_id" insert="false" update="false"/>
<set name="children" lazy="true" order-by="name" table="entity">
<key column="parent_id"/>
<one-to-many class="eg.Entity"/>
</set>
</class>
</hibernate-mapping>
Is this kind of mapping nonsense?
My "entity" can have a "parent entity" (or no parent) of type eg.Entity. In addition it can have a set of "child entities" that are of type eg.Entity too. Kind of a circular reference.
As I wrote before, I have a constraint in my database that prevents deletion on entities that have children, better saying, prevents deletion on entities whose ids are used by other entities in parent_id.
It works fine, but Hibernate is setting entity.parent_id to null on entities that have parent_id equals to the entity's id I want to delete, and it is done
before perform deletion. Thats the behaviour I would like to avoid, because
I wanna catch the JDBCException generated from the database by my constraint.
Is that possible?
Thanx.