-->
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.  [ 6 posts ] 
Author Message
 Post subject: Cache - Unable to see changes to DB
PostPosted: Wed Sep 21, 2005 3:52 pm 
Newbie

Joined: Mon Dec 13, 2004 12:29 pm
Posts: 3
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 2.1

I made some changes to the database directly and now I cannot see them using session.find. The table has a composite key and i have updated values in both keys. I use a JNDI to access the database

The strategies I have tried to get around this problem:

1. Set level 2 cache to false - did not work
<property name="hibernate.cache.use_second_level_cache">
false
</property>
2. Tried refreshing session, but since it cannot load the object I want, it did not help.

The same stuff works if I specify connection as a URL. I have gone through the posts, and tried different strategies. None helped.

Any help will be appreciated

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 21, 2005 7:43 pm 
Newbie

Joined: Thu Sep 08, 2005 9:27 am
Posts: 10
Hi sreerc,
First of all, are you sure changes have been actually done to the database?
If you enable show_sql property, when you commit your Transaction, does it perform an sql udpdate or insert?

In case it does:
I had a similar problem and I found out that sometimes it is better to close the session and open a new one to continue working.
I am working in a web environment and apparently opening a session and a transaction for each request is not a bad practice. Off course, some objects that should be controlled by hibernate and are kept in http session have to be reattached in order to make everything work.

In case it doesn't:
What do you mean by "I have updated both values" ? Was there an existing row for the object you are working with, or is it a transient object that doesn't get saved?

Waiting for more info...

Bye

_________________
Pablo N. Alvarez
Austral University
Argentina


Top
 Profile  
 
 Post subject: Thanks
PostPosted: Wed Sep 21, 2005 11:09 pm 
Newbie

Joined: Mon Dec 13, 2004 12:29 pm
Posts: 3
pablius,
Thanks immensely for the reply.
I updated the database outside of Hibernate and now I am unable to see the values that I updated.

I have a preference types table that is a FK in a business unit preference table. I added a bunch of values in preferences and for each of those I created rows in business unit preference. When I try to access business unit preference, I only get the values that were previously in cache.
There were 14 previously. Now there are 20, but I only see the 14.

I use Hibernate Synchronizer and it does create a new session for each query. Mine is a web environment, too.

Can you elaborate on
Quote:
objects that should be controlled by hibernate and are kept in http session have to be reattached in order to make everything work
[/code][/b]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 22, 2005 12:07 am 
Newbie

Joined: Thu Sep 08, 2005 9:27 am
Posts: 10
So you are saying you added those 14 values directly into your database and then when loading your business unit bean with hibernate it loaded its related 14 business unit preference beans.
Afterwards, you added 6 new business unit preference to the business unit but when loading it again it didn't show the changes. Am I right or did I misunderstand the design?
Maybe you should explain the tables and mapping with more detail, as well as the steps you followed to get there.

About the http session
In my app, users have to login, and when this happens, a user bean stays stored as an attribute in session.
Each user has a list of profiles which gives them access to different parts of the application and enables certain operations. This list is lazily loaded.

After the user bean has been loaded by hibernate and stored in the http session, the request finishes and the bean is detached from hibernate session (because it gets closed).
During the next request, I may need to get some info from one of this profiles but when accessing the user bean's list, it won't be able to return any profile, because they are lazily loaded and the user bean is detached from the previously closed hibernate session.
What I have to do is to reattach the user bean to the request's current hibernate session and then ask for a certain profiles bean.

This work isn't necessary if you take the long session approach, but it surely has it's own problems wich are not easy to deal with. (e.g.: atomicity and cache issues)

_________________
Pablo N. Alvarez
Austral University
Argentina


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 22, 2005 7:26 am 
Newbie

Joined: Mon Dec 13, 2004 12:29 pm
Posts: 3
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping package="com.lxnx.fab.ess.DAO">
   <class name="EssTpreferences" table="ESS_TPREFERENCES">
      <id
         column="PREF_PREFERENCE_TYPE"
         name="PrefPreferenceType"
         type="string"
      >
         <generator class="assigned" />
      </id>
      <property
         column="BUSU_UNIT_CODE"
         length="10"
         name="BusuUnitCode"
         not-null="false"
         type="string"
       />
      <property
         column="PREF_PREFERENCE_DESCRIPTION"
         length="50"
         name="PrefPreferenceDescription"
         not-null="false"
         type="string"
       />
   </class>
</hibernate-mapping>

I added 4 preferences.

For the next one I added 6 values for the above preferences.

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping package="com.lxnx.fab.ess.DAO">
   <class name="EssTbusinessUnitPreferences" table="ESS_TBUSINESS_UNIT_PREFERENCES">
      <composite-id class="EssTbusinessUnitPreferencesPK" name="Id">
         <key-property
            column="PREF_PREFERENCE_TYPE"
            name="PrefPreferenceType"
            type="string"
          />
         <key-many-to-one
            class="EssTbusinessUnits"
            column="BUSU_UNIT_CODE"
            name="BusuUnitCode"
          />
      </composite-id>
      <property
         column="PREF_PREFERENCE_VALUE"
         length="50"
         name="PrefPreferenceValue"
         not-null="false"
         type="string"
       />
   </class>
</hibernate-mapping>


I am trying to access data from business unit preferences. It's simple
Code:
create session from session factory
session.find(query)
close session

I use EhCache 1.1 - which states that find on a primary object will go to the DB, but not for secondary tables. So, I tried loading the prefereces first, but it did not help; it only loads the initial set of values.

I tried setting cache to false; did not help. I dont need caching, since the database is not very large. Is there someway to completely turn off the cache?


Top
 Profile  
 
 Post subject: About the cache issue
PostPosted: Fri Sep 23, 2005 12:16 am 
Newbie

Joined: Thu Sep 08, 2005 9:27 am
Posts: 10
I have to admit that I haven't studied hibernate cache system yet, but I know ehCache is the second level cache provider. It is useful only with read-only classes or for concurrency issues.

The first level cache is managed by hibernate session and it cannot be turned off, because an hibernate session has a transaction scope. When I started with this project, I made a mistake and left an hibernate session opened as long as the http session was. Off course, I could never see my changes to the database, queries always returned the same set of values.

Maybe you are trying to save the new objects (or relationships) and then make the query in the same hibernate session. You have to close it and open a new session, or clear() the current session to evict all associated instances.

Hope it helps...

_________________
Pablo N. Alvarez
Austral University
Argentina


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