-
1. Re: Hibernate Cache
joaobmonteiro Jun 18, 2008 4:04 PM (in response to viniciuscarvalho.viniciusccarvalho.gmail.com)Hi Vinicius,
Did you enable query cache in hibernate.cfg.xml?
Something like:
hibernate.cache.usequerycache trueQuery cache only caches identifiers, not entire results, so you need second-level cache to avoid database queries.
Seeya
-
2. Re: Hibernate Cache
viniciuscarvalho.viniciusccarvalho.gmail.com Jun 18, 2008 5:44 PM (in response to viniciuscarvalho.viniciusccarvalho.gmail.com)Well Ive set it up on my persistence.xml I do have caching for both quries and objects on other projects, but those are 100% hibernate. The whole JPA is that's making me believe I cant get it working.
<properties> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/> <property name="hibernate.hbm2ddl.auto" value="update"/> <property name="hibernate.show_sql" value="true"/> <property name="hibernate.format_sql" value="true"/> <property name="jboss.entity.manager.factory.jndi.name" value="java:/PortalSearchEntityManagerFactory"/> <property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"/> <property name="hibernate.cache.use_query_cache" value="true"/> </properties>
Regards
-
3. Re: Hibernate Cache
joaobmonteiro Jun 18, 2008 9:42 PM (in response to viniciuscarvalho.viniciusccarvalho.gmail.com)Hi Vinicus,
I use second-level cache and query cache with JPA plus Hibernate and it works fine.
I know it could sound silly but review your configuration because you are injecting Hibernate Session and configuring an EntityManagerFactory using JNDI. Looks strange to me.Verify your components.xml and check if the Session component is configured correctly. I think maybe your injected Session is not using your persistence.xml.
Regards
-
4. Re: Hibernate Cache
viniciuscarvalho.viniciusccarvalho.gmail.com Jun 19, 2008 3:05 PM (in response to viniciuscarvalho.viniciusccarvalho.gmail.com)Well, I have the session configured as a factory component as explained at the seam docs:
<core:manager conversation-timeout="120000" concurrent-request-timeout="500" conversation-id-parameter="cid"/> <persistence:managed-persistence-context name="entityManager" auto-create="true" persistence-unit-jndi-name="java:/PortalSearchEntityManagerFactory"/> <factory name="session" value="#{entityManager.delegate}" scope="stateless" auto-create="true"/> <!--<transaction:ejb-transaction/> --><security:identity authenticate-method="#{authenticator.authenticate}"/> </components>
So, my session is being created from my entityManager. I'm still looking for what could be the reason, but so far nothing.
If only java had support for collections query, I could store my entire table (which may never get to 20 rows), and query the collection. Sometimes I have this strange feeling that C sharp is kicking java's ass :)