-->
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.  [ 1 post ] 
Author Message
 Post subject: Load whole table into the Cache
PostPosted: Wed Jul 08, 2009 6:26 am 
Newbie

Joined: Wed Jul 01, 2009 10:56 am
Posts: 7
Hello, i have a table, which i want to use many times, so i want to get my whole table into the cache (using ehcache, altho i only need 1st lvl cache for now), and then get the objects by id, from the cache.
Im trying to only make one database connection.


I have this code (query cache activated and working), but if i executte this

Query q = session.getNamedQuery("MuniYProvinci");
q.setCacheable(true);
q.list();


q = session.getNamedQuery("MuniYProvinciIndi").setLong("id", 1);
q.setCacheable(true);
q.list();

the second query will also connect to the database (i want it to return the object 1 from cache)

This is my mapping

<?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="pruebahibernate_1.MuniYProvincia"
table="XXX"
lazy="false">
<cache usage = "read-only"/>
<composite-id
name="pkm"
class="pruebahibernate_1.PKMunicipio" >

<key-property name="municipio"/>
<key-property name="provincia"/>

</composite-id>
<property name="zonavd" column="zona_vd"/>
<property name="descripcion"/>
</class>


<query name="MuniYProvinciIndi">
SELECT pkm,
descripcion,
zonavd
FROM pruebahibernate_1.MuniYProvincia A
WHERE pkm.municipio=:id
</query>
<query name="MuniYProvinci">
SELECT descripcion,
zonavd
FROM pruebahibernate_1.MuniYProvincia
</query>
</hibernate-mapping>

PS: If some1 know how to do this using get() and load() (loading the whole table to cache), that will solve my problem too.
PS2: I know that i can search the list, but i want to avoid that if possible =).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.