-->
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.  [ 7 posts ] 
Author Message
 Post subject: Second-level cache & one-to-one : Objects not uptodate
PostPosted: Thu May 27, 2004 7:45 am 
Newbie

Joined: Thu Feb 26, 2004 10:19 am
Posts: 8
Location: Passau, Germany
Hi to everybody!
We use hibernate in a mid-sized project.
We use Hibernate 2.1.2 with ehcache as Second-level Cache.

I have now two classes mapped by one-to-one: (see attached mapping files)
MainObject and Object2, each of them using the second-level cache ("usage=read-write")
..within the application there is a sequence of three transactions (TR):
Each of the transactions starts with
Code:
Session session = factory.openSession();
Transaction tx = session.beginTransaction();

and ends with
Code:
tx.commit();
session.close();


TR1:
create and save an instance of MainObject

TR2:
load an existing MainObject
create an instance of Object2
set references from MainObject to Object2 and vice-versa
(Object2 is saved because of cascade-all-mapping)

TR3:
load the MainObject

THE PROBLEM:
The Object2 is correctly saved to the database (a postgresql 7.4) but MainObject.getObject2() will return null in TR3.
Only some minutes later MainObject "knows" its Object2 and returns it correctly by MainObject.getObject2()

If I use one-to-many mapping in MainObject instead of one-to-one, this problem does not appear.
Since our transactions are strongly capsulated to abstract from hibernate, I cannot call sessionFactory.evict(MainObject.class), which would be -in this small testcase- another solution to the problem.

My Mapping-Files:

Code:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class
        name="cachetest.MainObject"
        table="mainobject"
        dynamic-update="false"
        dynamic-insert="false"
    >
        <cache usage="read-write" />

        <id
            name="id"
            column="id"
            type="java.lang.Long"
        >
            <generator class="native">
                <param name="sequence">seq_mainobj</param>
            </generator>
        </id>

        <one-to-one
            name="obj2"
            class="cachetest.Object2"
            cascade="all"
            outer-join="auto"
            constrained="false"
        />

        <property
            name="description"
            type="java.lang.String"
            update="true"
            insert="true"
            column="description"
        />

    </class>

</hibernate-mapping>


Code:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class
        name="cachetest.Object2"
        table="object2"
        dynamic-update="false"
        dynamic-insert="false"
    >
        <cache usage="read-write" />

        <id
            name="id"
            column="id"
            type="java.lang.Long"
        >
            <generator class="foreign">
                <param name="property">belongsToMainObj</param>
            </generator>
        </id>

        <property
            name="dummy"
            type="java.lang.String"
            update="true"
            insert="true"
            column="dummy"
        />

        <one-to-one
            name="belongsToMainObj"
            class="cachetest.MainObject"
            cascade="none"
            outer-join="auto"
            constrained="true"
        />

    </class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 27, 2004 8:51 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Whats your cache configuration? Also did you try it with 2.1.3, there was a bit of cache-related bugfixing ...


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 27, 2004 11:39 am 
Newbie

Joined: Thu Feb 26, 2004 10:19 am
Posts: 8
Location: Passau, Germany
I have now run my testcase under Hibernate 2.1.3, too.
No change. The same problem occurs.

I have to admit that until now, I didn't even know that you can configure EHCache. So I (or more likley ehcache) use the default ehcache-failsafe.xml configuration-file from the ehcache-0.7.jar.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 27, 2004 12:13 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Can you check if in the "some Minutes later" case, the MainObject is loaded from the cache or from the db? Take a look at the log to check.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 28, 2004 2:56 am 
Newbie

Joined: Thu Feb 26, 2004 10:19 am
Posts: 8
Location: Passau, Germany
The some-minutes later case is quite exactly after 120 seconds, which is exactly the time-to-live in ehcache-failsafe.xml.
The MainObject is then -for the first time after the update- fetched from the database.
[At least this is the first time, that show-sql=true will print a new sql-select-statement, whereas in the first 100 seconds a session.load of MainObject does not provoke any database-access.]


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 28, 2004 9:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
hum, I think this might be a bug in Hibernate. Please submit a simple test case to JIRA.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 03, 2004 4:27 am 
Newbie

Joined: Thu Feb 26, 2004 10:19 am
Posts: 8
Location: Passau, Germany
Great job !

The problem seems really already be fixed in 2.1.4.
Many thanks to the hibernate team for its fast reaction !!!


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