2 Replies Latest reply on Oct 31, 2007 6:03 AM by Endre Midtgaard Meckelborg

    Problem with cache config in unit tests

    Endre Midtgaard Meckelborg Newbie

      Hi!

      I have a Seam application (v1.2.1) where I have started to use JBoss Cache as an entity cache. The application is deployed within JBoss 4.0.4, and things seems to work. I use the following config in "persistence.xml":

       <persistence-unit name="NewsAdminSesamNoDatabase">
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/NewsAdminSesamNoDS</jta-data-source>
       <properties>
       <!-- Uses JBoss Cache as entity cache. -->
       <property name="hibernate.cache.provider_class" value="org.jboss.ejb3.entity.TreeCacheProviderHook"/>
       <property name="hibernate.treecache.mbean.object_name" value="jboss.cache:service=EJB3EntityTreeCache"/>
       <!-- Enabled query cache. -->
       <property name="hibernate.cache.use_query_cache" value="true"/>
       </properties>
       </persistence-unit>
      


      The problem is that my tests now breaks because I can't manage to get things running in the embedded jboss. Usually I use ehcache in my tests using the provider class "HashtableCacheProvider", defined in "default.persistence.properties".

      But the TreeCache config in "persistence.xml" seems to override my test config. I have tried to include jboss-cache in my test classpath, but then my tests fail since "EJB3EntityTreeCache" is not deployed, and I don't know how I can do this.

      Anybody that can give me an advice how to solve this?

      Thanks :)

        • 1. Re: Problem with cache config in unit tests
          Damian Harvey Master

          How are you creating your EntityManager in your unit tests? Are you able to just create a separate persistence-unit for your tests?

          Cheers,

          Damian.

          • 2. Re: Problem with cache config in unit tests
            Endre Midtgaard Meckelborg Newbie

            Sorry for that missing info...

            I use both unit tests where I create my components myself, but I also use FacesRequest tests where the EM's is injected automatically.

            My embedded EM's are configured in "embedded-jboss-beans.xml":

             <bean name="NewsAdminSesamNoDSBootstrap" class="org.jboss.resource.adapter.jdbc.local.LocalTxDataSource">
             <property name="driverClass">org.hsqldb.jdbcDriver</property>
             <property name="connectionURL">jdbc:hsqldb:.</property>
             <property name="userName">sa</property>
             <property name="jndiName">java:/NewsAdminSesamNoDS</property>
             <property name="minSize">0</property>
             <property name="maxSize">10</property>
             <property name="blockingTimeout">1000</property>
             <property name="idleTimeout">100000</property>
             <property name="transactionManager"><inject bean="TransactionManager"/></property>
             <property name="cachedConnectionManager"><inject bean="CachedConnectionManager"/></property>
             <property name="initialContextProperties"><inject bean="InitialContextProperties"/></property>
             </bean>
            
             <bean name="NewsAdminSesamNoDS" class="java.lang.Object">
             <constructor factoryMethod="getDatasource">
             <factory bean="NewsAdminSesamNoDSBootstrap"/>
             </constructor>
             </bean>
            


            I thought that this was the thing that created my entity managers, but the properties in "persistence.xml" is also used, and this triggers the tree cache connection.