-->
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: Browse hibernate cache
PostPosted: Wed Aug 03, 2005 5:48 am 
Newbie

Joined: Wed Jun 30, 2004 4:50 am
Posts: 12
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.0.5

Mapping documents:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>

<property name="hibernate.max_fetch_depth">1</property>
<property name="hibernate.auto_close_session">true</property>
<property name="hibernate.connection.isolation">2</property>
<property name="hibernate.cglib.use_reflection_optimizer">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.use_outer_join">true</property>

<!-- Connection pool related properties -->
<property name="hibernate.connection.provider_class">org.hibernate.connection.ProxoolConnectionProvider</property>
<property name="hibernate.proxool.properties">proxool.properties</property>
<property name="hibernate.proxool.pool_alias">hibernateConnPool</property>

<!-- Cache related properties -->
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.OSCacheProvider</property>

</session-factory>
</hibernate-configuration>


<?xml version="1.0" encoding="UTF-8"?>

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

<hibernate-mapping
>
<class
name="com.mintnovate.common.entities.Address"
table="cm_address"
dynamic-update="true"
>
<cache usage="read-write" />

<id
name="id"
column="id"
type="java.lang.String"
length="32"
unsaved-value="null"
>
<generator class="assigned">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Address.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>

<property
name="building"
type="java.lang.String"
update="true"
insert="true"
column="building"
length="60"
not-null="true"
/>

<property
name="city"
type="java.lang.String"
update="true"
insert="true"
column="city"
length="20"
not-null="true"
/>

<property
name="country"
type="java.lang.String"
update="true"
insert="true"
column="country"
length="5"
not-null="true"
/>

<property
name="floor"
type="java.lang.String"
update="true"
insert="true"
column="floor"
length="10"
not-null="true"
/>

<property
name="location"
type="java.lang.String"
update="true"
insert="true"
column="location"
length="20"
not-null="true"
/>

<property
name="street"
type="java.lang.String"
update="true"
insert="true"
column="street"
length="60"
not-null="true"
/>

<property
name="state"
type="java.lang.String"
update="true"
insert="true"
column="state"
length="20"
not-null="true"
/>

<property
name="unit"
type="java.lang.String"
update="true"
insert="true"
column="unit"
length="10"
not-null="true"
/>

<property
name="ownerId"
type="java.lang.String"
update="true"
insert="true"
column="owner_id"
length="32"
not-null="true"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Address.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>




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

Full stack trace of any exception that occurs:

Name and version of the database you are using:MySQL v5

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Hi hibernate gurus, Need your help. We enabled caching for our web application using OS cache. Most of our hibernate entities are configured to use "read-write" cache. But it seems everytime hibernate is loading the entities from DB instead of getting from cache, which were already loaded. I am not sure of what is going wrong. Can you please suggest me the possible errors we could have made.
Also is there a way to find out currently what entities are being cached.
I am providing the hibernate.cfg.xml and one of the mapping file for your reference of config.


Thanks alot.


Top
 Profile  
 
 Post subject: Reasons?
PostPosted: Wed Aug 03, 2005 4:16 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Just for fun I used your mapping and it looks like cache works just fine.
What are reasons for you to believe that cache is not working.


Code:
public void test(Session s) throws Exception {
    Object o = s.load( Address.class, "a");
    System.out.println("o = " + o);
    closeSession();
    s = currentSession();
    for( int i = 0; i < 10;i++){
      o = s.load( Address.class, "a");
      System.out.println("o = " + o);
    }
  }


There were two separate sessions and only one SQL was submitted to DB.

(Tested against H3.1-cvs)


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.