Hibernate saveOrUpdate () doesn't seem to create and save cascade

I am new to Hibernate and am trying to store "UserState" with a "WorkspaceState" list. UserStates are injected using the username that is set, WorkspaceStates are set using the UUID schema. My problem is that if I have a UserState with one WorkspaceState in it, the UserState will be saved, but the WorkspaceState will not.

Here is the Hibernate mapping

    <class name="UserState" table="USERSTATE">
        <id name="owner" type="java.lang.String">
            <column name="OWNER" />
            <generator class="assigned" />
        <list name="workspaces" inverse="false" cascade="all" table="WORKSPACESTATE" lazy="true">
                <column name="UID" />
            <one-to-many class="WorkspaceState" />

    <class name="WorkspaceState" table="WORKSPACESTATE">
        <id name="uid" type="java.lang.String">
            <column name="UID" />
            <generator class="uuid" />
        <property name="owner" type="java.lang.String">
            <column name="OWNER" />


I have a UserState object with one WorkspaceState in it. When I do session.saveOrUpdate (userst) I can see that hibernate has already removed the WorkspaceState from my custom object. Then the commit saves it to the database without the workspacestate function.

In truth, the WorkspaceStates themselves have lists, but I suspect that whatever I am doing wrong continues on.


Change - how it was done. HibernateUtil is as shown in the standard hibernate docs:

Session session = HibernateUtil.getSessionFactory().openSession();
Transaction transaction = null;

try {
    transaction = session.beginTransaction();
    String username = (String) session.merge(state);
} catch (HibernateException e) {
    return false;
} finally {



source to share

1 answer

you need to change the cascade link to save-update and remove the inverse attribute from the job list display



All Articles