-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate Bug?
PostPosted: Thu Mar 03, 2005 11:58 am 
Newbie

Joined: Wed Jan 19, 2005 2:24 pm
Posts: 9
Hibernate version:

2.1.8

Mapping documents:

Code:
    <class name="Process" table="workflow_process">
        <cache usage="transactional" />
        <id name="id" column="id" type="java.lang.Long"  unsaved-value="null">
            <generator class="increment"/>
        </id>

        <property name="description" column="description"   type="string" />
        <property name="state"       column="process_state" type="java.lang.Long" />
        <property name="status"      column="status"        type="java.lang.Long" />
        <property name="createdBy"   column="created_by"    type="string" not-null="true" />
        <property name="createdOn"   column="created_on"    type="java.util.Date" not-null="true" />
        <many-to-one name="accData" column="acc_id" class="ProcessAccounting" cascade="all"/>

</class>


Code:
    <class name="ProcessAccounting" table="workflow_pr_acc" >
        <id name="id" column="id" type="java.lang.Long" unsaved-value="null">
            <generator class="increment"/>
        </id>

        <property name="commission" column="commission" type="java.lang.Long"/>
</class>


Code between sessionFactory.openSession() and session.close():

map is a Map that contains bean property names mapped to the values of the properties.
process is an instance of Process as per the above mappings

Code:
        process.setProperties(map);
       process.getAccData().setProperties(map);


The method setProperties is as follows:

Code:
    public final void setProperties(Map properties)
    {
        try
        {
            PropertyUtils.copyProperties(this, new LazyDynaMap(properties));
        }
        catch (IllegalAccessException e)
        {
            e.printStackTrace();
        }
        catch (InvocationTargetException e)
        {
            e.printStackTrace();
        }
        catch (NoSuchMethodException e)
        {
            e.printStackTrace();
        }
    }


Full stack trace of any exception that occurs:

No exceptions occur but only the top-level object's new values are persisted to the database.

The following

Code:
process.setProperties(myMap);


works fine. The new values are persisted to the DB.

but

Code:
process.getAccountingData().setProperties(myMap);


reports new values in the session cache, but does not persist any changes to the database. For example:

Code:
// we have a processAccounting object of type ProcessAccounting
// the following line reports the old value, which is 10
logger.debug("Commission :: " + processAccounting.getCommission());
Map map = new HashMap();
map.put("commission", new Long(20));
processAccounting.setProperties(map);
session.saveOrUpdate(processAccounting);
// the following line reports the new value, which is 20
logger.debug("Commission :: " + processAccounting.getCommission());
session.flush();
//and the DB still has 10!


Name and version of the database you are using:

MySQL 4.1


Top
 Profile  
 
 Post subject: Re: Hibernate Bug?
PostPosted: Thu Mar 03, 2005 12:02 pm 
Newbie

Joined: Wed Jan 19, 2005 2:24 pm
Posts: 9
p_kirill wrote:
session.saveOrUpdate(processAccounting);


the above line should be:

Code:
session.saveOrUpdate(process)


Supposedly, this should persist the ProcessAccounting object as well (called accData in the mapping above), but it does not.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 03, 2005 1:26 pm 
Newbie

Joined: Wed Jan 19, 2005 2:24 pm
Posts: 9
Addition to my previous post:

This problem appears to be unrelated to Map. The following code does not persist changes either (an instance with ID == 2 already exists in the DB):

Code:
            ProcessAccounting pa2 = (ProcessAccounting)
                    session.get(ProcessAccounting.class, new Long(2));
            logger.info(">>>>commission == " + pa2.getCommission()); //output is null (correct)
            pa2.setCommission(new Long(40));
            session.saveOrUpdate(pa2);
            logger.info(">>>>commission == " + pa2.getCommission()); //output is 40 (correct)
            flush();


No changes in the DB (MySQL 4.1.)

This is the Hibernate log:

Code:
03-03-2005 17:52:16 DEBUG net.sf.hibernate.type.LongType - binding '2' to parameter: 1
03-03-2005 17:52:16 DEBUG net.sf.hibernate.loader.Loader - processing result set
03-03-2005 17:52:16 DEBUG net.sf.hibernate.type.LongType - returning null as column: id0_
03-03-2005 17:52:16 DEBUG net.sf.hibernate.loader.Loader - result row: null, 2
03-03-2005 17:52:16 DEBUG net.sf.hibernate.loader.Loader - Initializing object from ResultSet: 2
03-03-2005 17:52:16 DEBUG net.sf.hibernate.loader.Loader - Hydrating entity: net.bookingasp.data.workflow.process.pojo.ProcessAccounting#2
03-03-2005 17:52:16 DEBUG net.sf.hibernate.type.LongType - returning null as column: invoice_6_1_
03-03-2005 17:52:16 DEBUG net.sf.hibernate.type.StringType - returning null as column: confirma7_1_
03-03-2005 17:52:16 DEBUG net.sf.hibernate.type.StringType - returning null as column: invoice_8_1_
03-03-2005 17:52:16 DEBUG net.sf.hibernate.type.TimestampType - returning null as column: confirma9_1_
03-03-2005 17:52:16 DEBUG net.sf.hibernate.type.TimestampType - returning null as column: invoice10_1_
03-03-2005 17:52:16 DEBUG net.sf.hibernate.type.BooleanType - returning 'false' as column: paid1_
03-03-2005 17:52:16 DEBUG net.sf.hibernate.loader.Loader - done processing result set (1 rows)
03-03-2005 17:52:16 DEBUG net.sf.hibernate.impl.BatcherImpl - done closing: 0 open PreparedStatements, 0 open ResultSets
03-03-2005 17:52:16 DEBUG net.sf.hibernate.impl.BatcherImpl - closing statement
03-03-2005 17:52:16 DEBUG net.sf.hibernate.loader.Loader - total objects hydrated: 1
03-03-2005 17:52:16 DEBUG net.sf.hibernate.impl.SessionImpl - resolving associations for [net.bookingasp.data.workflow.process.pojo.ProcessAccounting#2]
03-03-2005 17:52:16 DEBUG net.sf.hibernate.impl.SessionImpl - done materializing entity [net.bookingasp.data.workflow.process.pojo.ProcessAccounting#2]
03-03-2005 17:52:16 DEBUG net.sf.hibernate.impl.SessionImpl - initializing non-lazy collections
03-03-2005 17:52:16 DEBUG net.sf.hibernate.impl.SessionImpl - saveOrUpdate() persistent instance
03-03-2005 17:52:16 DEBUG net.sf.hibernate.impl.SessionImpl - flushing session


Thanks for any pointers.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 03, 2005 2:51 pm 
Newbie

Joined: Wed Jan 19, 2005 2:24 pm
Posts: 9
Anyone has any idea why this would happen? I must be doing something wrong, but I really can't see what... it's so plain simple.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 04, 2005 9:34 am 
Newbie

Joined: Wed Jan 19, 2005 2:24 pm
Posts: 9
Just in case someone comes across a similar issue: The problem was that I accidentally mapped the same class and the same table to two different entities. That is, I put the same class name and the same table name in two mappings. Just a typo. Hibernate did not complain


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.