3 Replies Latest reply on Jul 8, 2011 10:16 AM by jamshed katta

    Hibernate in seam, Second-level caching problem

    David Doherty Newbie
      Hi guys, I'm going out of my mind trying to get hibernate working with seam. I already have an existing hibernate project that I want to use within the app. I am trying to strip it down to the basics and get it working with seam and then migrate the rest later.

      Here is my original hibernate config file that I tried. It used Ehcache as the second level cache. Even though it appears to reference the mapping and ehcache files without problem, I am having problems when the container is trying to instantiate the bean.

      <?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 name="java:/bookingSessionFactory">
              <property name="connection.datasource">java:jdbc/PIMSLocalTx</property>
              <property name="dialect">org.hibernate.dialect.SybaseDialect</property>
              <property name="hibernate.show_sql">false</property>
              <property name="cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
              <property name="hibernate.cache.provider_class">
                  org.hibernate.cache.EhCacheProvider
              </property>
              <property name="hibernate.cache.provider_configuration_file_resource_path">ehcache.xml</property>
              <property name="hibernate.cache.use_second_level_cache">true</property>

              <!-- Mapping files -->
              <mapping resource="Currency.hbm.xml"/>
          </session-factory>
      </hibernate-configuration>

      The error I receive is:

      Caused by: org.hibernate.HibernateException: Could not instantiate cache implementation
              at org.hibernate.cache.CacheFactory.createCache(CacheFactory.java:64)
              at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:214)
              at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
              at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:713)
              ... 153 more
      Caused by: org.hibernate.cache.NoCachingEnabledException: Second-level cache is not enabled for usage [hibernate.cache.use_second_level_cache | hibernate.cache.use_query_cache]
              at org.hibernate.cache.NoCacheProvider.buildCache(NoCacheProvider.java:21)
              at org.hibernate.cache.CacheFactory.createCache(CacheFactory.java:61)
              ... 156 more

      I then tried adding the property hibernate.cache.use_query_cache and set it to true, but that had no effect. Have I made a mistake in the config somewhere? I have tried making loads of little changes to the config to get it working but think I am missing something.

      Any help would be appreciated...

      Thanks,
      David