J. Doe
J. Doe

Reputation: 11

Mapping a map collection containing superclasses in Hibernate

I am trying to map a map collection of String, SuperClass using XML mapping files. Here's what I have:

<map name="mapName" cascade="all-delete-orphan">
    <key column="ID" />
    <index column="KEY" type="string" />
    <one-to-many class="SuperClass" />
</map>

The SuperClass has (currently one but probably going to need some more in the future) a subclass that I'm going to call SubClass. So I have a bunch of SubClass and SuperClass objects in the map and when Hibernate attempts to search for them after adding them I get a

org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

I'm pretty sure Hibernate is looking for classes of type SuperType when the objects in the map actually have some SubTypes as well.

Here's the gist of how the mapping was done for the hierarchy in case you need a better representation of what I'm talking about:

<class name="SuperClass" table="SUPER_CLASS">
    ...properties...
    (contains some <component> tags as well if it matters)
    <union-subclass name="SubClass" table="SUBCLASS">
        ...more properties...
    </union-subclass>
</class>

Upvotes: 1

Views: 137

Answers (0)

Related Questions