简体   繁体   中英

Hibernate not updating (merging) object

I have tag object that is driving me crazy. I'm trying to update it and every time I do everything seems OK until I check the database and it is not updated.

I'm having all the logging turned on but I don't see anything out of the ordinary.

Even after I create brand new object and try to update (or merge it) right after, it will not show in database. It will create the new object but it will not update it.

Did anyone have similar problem and how did you solve it?

<hibernate-mapping package="com.package">

<class name="com.package.Tag" table="tags" lazy="false" mutable="false" >
    <meta attribute="generated-class">com.package.generated.AbstractTag</meta>
    <meta attribute="scope-class">public abstract</meta>
    <cache usage="read-write"/>

    <id name="id" type="long" column="tag_id">
        <generator class="native"/>
    </id>


    <property name="name" type="string" column="name" unique="true"/>

    <property name="itemCount" type="integer" column="itemCount"/>

</class>

</hibernate-mapping>

Watch out for mutable="false" it makes the object imutable by the application:

As specified here: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html

mutable (optional - defaults to true): specifies that instances of the class are (not) mutable. Immutable classes, mutable="false", cannot be updated or deleted by the application. This allows Hibernate to make some minor performance optimizations.

Removing mutable="false" from the hbm file fixed the problem.

Have you tried setting (and saving) the Tag on the item, instead of adding items to the Tag class?

So basically doing what is required by the database, first creating a Tag (without any reference to items) and then creating items (records) with references to the Tag.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM