-->
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: Problem with Session cache
PostPosted: Sun Feb 19, 2006 8:59 pm 
Newbie

Joined: Sun Feb 19, 2006 8:40 pm
Posts: 3
Hibernate version: 3.1
Name and version of the database you are using: MySQL 5.0

hibernate.properties
...
hibernate.cache.provider_class=org.hibernate.cache.NoCacheProvider
hibernate.cache.use_query_cache=false
hibernate.cache.use_second_level_cache=false

Settings.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="com.dareit.warranty.mapping">
<class
name="Settings"
table="settings"
dynamic-insert="false"
dynamic-update="false">
<!--cache usage="read-write" /-->
<id
name="Id"
type="integer"
column="id"
>
<generator class="increment"/>
</id>
<property
name="SetKey"
column="set_key"
type="string"
not-null="false"
length="50"
/>
<property
name="SetValue"
column="set_value"
type="string"
not-null="false"
length="255"
/>
<property
name="Visible"
column="visible"
type="java.lang.Short"
not-null="false"
length="6"
/>
</class>
</hibernate-mapping>

I create a Session like this:
Code:
sf = c.buildSessionFactory();
      session = sf.openSession();


The problem is following:
1. I use application x with Hibernate to receive records from the table (in a transaction).
2. I modify a record with an external query (MySQL Command Line)
3. From the application x I make a new criteria list to get the newest records but I receive the old records (without last updates).
More details:
I use the same session for first and second criteria list.
The problem disapear if I made a session.clean() between first and second list, but I may not use clean because I loss some other important things from session (the application is more complex).

To make the problem simplier: I have to instances of application x in separate JVM that use the same MySQL server and have to take care about each modifications from the another application. I don't want to use at all cache systems.
What can be the easiest solution for this problem?
Sorry if the problem was described somewhere in the forum, I searched for a solution but I didn't find a good solution for this case.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 19, 2006 9:47 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
For Criteria, use setCacheMode(CacheMode.IGNORE).


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 20, 2006 3:48 am 
Newbie

Joined: Sun Feb 19, 2006 8:40 pm
Posts: 3
I've tried to use useCacheMode(CacheMode.IGNORE) and/or setCacheable(false) and it's not working. It has the same behavior.

I want to say that both cache mechanismes are disabled (the log sais this).
What other solutions do you have for this problem?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 20, 2006 4:37 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
I couldn't see much that selectively clears the session cache: there's much more control available over the second level cache. If you know that certain queries are susceptible to being invalidated like this, you could use a cache region and set CacheMode.REFRESH whenever you access it. As I understand it, that would effectively refresh all objects retrieved by the queries.
Code:
Query qry = sess.createQuery(...);
qry.setCacheRegion("autorefresh").setCacheMode(CacheMode.REFRESH);


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 21, 2006 9:36 am 
Newbie

Joined: Sun Feb 19, 2006 8:40 pm
Posts: 3
The problem was a little bit not like I wrote in the topic but I didn't know.
The problem was like this:
1. app x make an insert
2. app y make an insert
3. app x make an insert and throw Exception.
Why because it was a violation constraint at id. Why? Because in mapping file I put generator class="increment". I modify and I put generator class="native" and it's working fine.

Thx to @tenwit that with him help I discover the solution.

The topic can be closed.


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.