-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: problem after update/delete object
PostPosted: Sun May 31, 2009 1:55 am 
Newbie

Joined: Mon Mar 23, 2009 5:47 am
Posts: 5
I do not find any topics on my problem. After I change some field (i.e. "address"),and then update it to db. then content in db are changed. For example ,original:address = "room" ,current :address="room2". After I press update,the value displayed in webpage and database are correct. then I go to another page to view the result, the value changed back to original. When I refresh the page, it changed to current value(correct),and refresh again,it changed to original value(incorrect). The value changed every othertime when I refresh the page.
what's the reason? how to settle it?

Even terrible , when I delete an object, the other time when I refresh the view page, it display and disappear!

I think it is something with the session operation.
I do it with session.flush()/session.clear(),still no effect.

the mapping file:

Code:
<hibernate-mapping>
    <class name="com.xunan.sitexa.site.data.Site" table="T_Site" schema="dbo" catalog="sitexa">
        <id name="siteId" type="java.lang.String">
            <column name="SiteId" length="50"/>
            <generator class="assigned"/>
        </id>
        <many-to-one name="type" class="com.xunan.sitexa.site.data.SiteType" update="true" insert="true">
            <column name="TypeId" length="50" not-null="true"/>
        </many-to-one>
        <many-to-one name="parent" class="com.xunan.sitexa.site.data.Site" update="true" insert="true">
            <column name="ParentId" length="50"/>
        </many-to-one>
        <property name="name" type="java.lang.String">
            <column name="Name" length="200"/>
        </property>
        <property name="createDate" type="java.util.Date">
            <column name="CreateDate" length="23"/>
        </property>
        <property name="address" type="java.lang.String">
            <column name="Address" length="500"/>
        </property>
        <property name="status" type="java.lang.Boolean">
            <column name="Status" length="1" not-null="true"/>
        </property>
        <many-to-one name="governor" class="com.xunan.sitexa.user.data.Member">
            <column name="Governor" length="50"/>
        </many-to-one>
        <property name="introduction" type="java.lang.String">
            <column name="Introduction" length="1000"/>
        </property>
        <property name="longitude" type="java.lang.Float">
            <column name="Longitude"/>
        </property>
        <property name="latitude" type="java.lang.Float">
            <column name="Latitude"/>
        </property>
        <property name="zoom" type="java.lang.Integer">
            <column name="Zoom"/>
        </property>
        <property name="vwCnt" type="java.lang.Integer">
            <column name="VwCnt"/>
        </property>
        <set name="properties" inverse="true" order-by="propId">
            <key>
                <column name="SiteId" length="50" not-null="true"/>
            </key>
            <one-to-many class="com.xunan.sitexa.site.data.SiteProperty"/>
        </set>
        <set name="pictures" inverse="true" order-by="picId">
            <key>
                <column name="SiteId" length="50" not-null="true"/>
            </key>
            <one-to-many class="com.xunan.sitexa.site.data.SitePicture"/>
        </set>
        <set name="children" inverse="true" order-by="siteId">
            <key>
                <column name="ParentId" length="50" not-null="true"/>
            </key>
            <one-to-many class="com.xunan.sitexa.site.data.Site"/>
        </set>
        <set name="members" inverse="true" order-by="siteId">
            <key>
                <column name="SiteId" length="50" not-null="true"/>
            </key>
            <one-to-many class="com.xunan.sitexa.site.data.SiteMember"/>
        </set>
    </class>
</hibernate-mapping>


and the DAO class
Code:
    public Session getSession() {
        if (null == this.session)
            session = HibernateSessionFactory.getSession();
        return session;
    }

    protected void delete(Object object) {
        Transaction tx = session.beginTransaction();
        tx.begin();
        session.delete(object);
        tx.commit();
        session.flush();
        session.clear();
    }

    protected void save(Object object) {
        Transaction tx = session.beginTransaction();
        tx.begin();
        session.save(object);
        tx.commit();
    }

    protected void update(Object object) {
        Transaction tx = session.beginTransaction();
        tx.begin();
        session.update(object);
        tx.commit();
    }

    protected void saveOrUpdate(Object object) {
        Transaction tx = session.beginTransaction();
        tx.begin();
        session.saveOrUpdate(object);
        tx.commit();
    }


Top
 Profile  
 
 Post subject: Re: problem after update/delete object
PostPosted: Mon Jun 01, 2009 8:29 am 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
Make sure you are not having duplicate objects - one for displaying and another for persisting. Please post the snippent where you call the save method and the snippet where you render the screen.

_________________
Sukirtha


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.