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 =).
|