5 Replies Latest reply on Jan 7, 2005 11:36 AM by Ben Wang

    Problem with Hibernate and jbossCache

    Carlos Miranda Newbie

      Hello all,
      I have a problem with my application , I use Hibernate 2.1.7c and jbosscache 1.1.1
      My hibernate entities is not use cache ( in hbm files declaration ) , but when I do execute :
      session.save ( pojo ) ;
      I see in my log file , a put in tree cache .

      Any idea ?

      thanks.-

      /Carlos.-

        • 1. Re: Loading interceptor classes at run-time DR3
          Ben Wang Master

           

          "rkadayam" wrote:
          1) I'm using jboss-aop with some other application servers such as weblogic and websphere. Would this usage construe as a jboss license violation?? The basic stuff works with weblogic 8.1


          Absolutely not as JBoss-AOP is distributed under LGPL. You can embed it anywhere. LGPL is only triggered when you modify JBoss-AOP code.

          "rkadayam" wrote:

          2) I'd like to jar load the interceptor classes at run-time and dynamically attach and detach interceptors to advice bindings.

          I noticed that the AdviceBinding.addInterceptor(Class) takes only a "class argument". How can I ask the aspect manager to use a particular class-loader to resolve that class?

          I tried the following from a session bean.

          addNewInterceptor(classname) -> jar loads the class file using some jar-directory conventions and is able to render the interceptor class

          attachInterceptor(pointcut,interceptor) -> does the following

          AdviceBinding binding = new AdviceBinding(pointcut,null);
          binding.addInterceptor(jarLoader.loadClass(interceptor));
          aspectManager.addBinding(binding);

          At the point of adding the binding I get the ClassNotFoundException initiated at the GenericInterceptorFactory. Oh! So do I provide a custom "JarLoadingInterceptorFactory" then? I'm going to try that out.

          any comments/suggestions would be greatly appreciated

          thanks
          rajiv


          Ok, I've changed the code in CVS head to not create a GenericInterceptorFactory using the classname, but rather it can accept the java.lang.Class itself so this should solve the problem if you get from head.

          You can get latest from CVS and build, or, in the meantime, the problem is that the GenericInterceptorFactory doesn't try and resolve the class until advice bind time. What you may be able to do is the following

          Class interceptorClass = ....;
          Thread.currentThread().setContextClassLoader(interceptorClass.getClassLoader);
          AdviceBinding.addInterceptor(interceptorClass);
          aspectManager.addBinding(binding);
          


          Let me know if this helps.

          Bill

          • 2. Re: Problem with Hibernate and jbossCache
            Ben Wang Master

            Hmmn! I have no idea why. If secondary cache is not set, TreeCache should not be invoked.

            Have you tried the Hibernate JBoss forum there?

            -Ben

            • 3. Re: Problem with Hibernate and jbossCache
              Carlos Miranda Newbie

              Ben,
              See my HBM files , java code and log file :
              HBM:
              <?xml version="1.0"?>
              <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
              "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
              <hibernate-mapping>


              <id name="id" unsaved-value="null" column="ID" type="java.lang.String">


              <many-to-one name="impuesto"
              class="gov.afip.pampa.component.supa.model.ImpuestoEntity"
              column="CODIGO_IMPUESTO"/>
              <many-to-one name="concepto"
              class="gov.afip.pampa.component.supa.model.ConceptoEntity"
              column="CODIGO_CONCEPTO"/>











              </hibernate-mapping>



              -----------------------

              CODE FILE:


              SessionFactory sessions =
              new Configuration().configure("/META-INF/ctacte-session-factory.cfg.xml")
              .buildSessionFactory();

              Session s = sessions.openSession();

              ICEntity ic = new ICEntity();
              ic.setId("ID_EX");

              s.save(ic);
              s.flush(); // here propagate to L2
              s.close();

              -----------------------------------------------

              Configuration Session

              <?xml version='1.0' encoding='utf-8'?>
              <!DOCTYPE hibernate-configuration PUBLIC
              "-//Hibernate/Hibernate Configuration DTD 2.0//EN"

              "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

              <hibernate-configuration>

              <!-- a SessionFactory instance listed as /jndi/name -->
              <session-factory>
              <!-- este es datasource para correr con jboss -->
              java:/PampaDS
              true
              true

              net.sf.hibernate.dialect.OracleDialect

              net.sf.hibernate.transaction.JTATransactionFactory

              net.sf.hibernate.transaction.JBossTransactionManagerLookup
              true
              true

              net.sf.hibernate.cache.TreeCacheProvider
              ctacte
              <!-- este es factory para correr unit test -->
              <!--
              develop
              develop
              jdbc:oracle:thin:@10.20.108.187:1521:OCRP
              oracle.jdbc.driver.OracleDriver
              true
              true
              net.sf.hibernate.dialect.OracleDialect
              net.sf.hibernate.cache.OSCacheProvider
              false
              -->


              </session-factory>

              </hibernate-configuration>


              -----------------------------

              Log File


              4:48:07,765 DEBUG [SessionImpl] executing flush
              14:48:07,765 DEBUG [TreeCache] _put(null, "//net/sf/hibernate/cache/UpdateTimestampsCache/SUPA.IC_ENTITY", item, 11051201477)
              14:48:07,765 DEBUG [Node] createChild: fqn=//net/sf/hibernate/cache/UpdateTimestampsCache
              14:48:07,765 DEBUG [LRUPolicy] nodeAdded(): fqn- //net/sf/hibernate/cache/UpdateTimestampsCache
              14:48:07,765 DEBUG [RegionManager] getRegion(): not user-specified region found for this fqn- //net/sf/hibernate/cache/UpdateTimestampsCache will use the global default region
              14:48:07,765 DEBUG [Node] createChild: fqn=//net/sf/hibernate/cache/UpdateTimestampsCache/SUPA.IC_ENTITY
              14:48:07,765 DEBUG [LRUPolicy] nodeAdded(): fqn- //net/sf/hibernate/cache/UpdateTimestampsCache/SUPA.IC_ENTITY
              14:48:07,765 DEBUG [RegionManager] getRegion(): not user-specified region found for this fqn- //net/sf/hibernate/cache/UpdateTimestampsCache/SUPA.IC_ENTITY will use the global default region
              14:48:07,765 DEBUG [LRUPolicy] nodeModified(): redirecting to node visited. fqn- //net/sf/hibernate/cache/UpdateTimestampsCache/SUPA.IC_ENTITY
              14:48:07,765 DEBUG [LRUPolicy] nodeVisited(): fqn- //net/sf/hibernate/cache/UpdateTimestampsCache/SUPA.IC_ENTITY
              14:48:07,765 DEBUG [RegionManager] getRegion(): not user-specified region found for this fqn- //net/sf/hibernate/cache/UpdateTimestampsCache/SUPA.IC_ENTITY will use the global default region
              14:48:07,765 DEBUG [EntityPersister] Inserting entity: [gov.afip.pampa.component.supa.model.ICEntity#ID_EX]
              14:48:07,765 DEBUG [BatcherImpl] about to open: 0 open PreparedStatements, 0 open ResultSets
              14:48:07,765 DEBUG [SQL] insert into SUPA.IC_ENTITY (CODIGO_IMPUESTO, CODIGO_CONCEPTO, PERIODO_DESDE, PERIODO_HASTA, FECHA_DESDE, FECHA_HASTA, ID) values (?, ?, ?, ?, ?, ?, ?)



              Any Help ?

              /Carlos.-


              • 4. Re: Problem with Hibernate and jbossCache
                Ben Wang Master

                Your xml file is garbled so it's difficult to tell. But make sure you have comment out the TreecacheProvider for the second level cache in Hibernate.

                -Ben

                • 5. Re: Problem with Hibernate and jbossCache
                  Carlos Miranda Newbie

                  Ben ,
                  Sorry , I resend a configuration file :

                  <?xml version='1.0' encoding='utf-8'?>
                  <!DOCTYPE hibernate-configuration PUBLIC
                   "-//Hibernate/Hibernate Configuration DTD 2.0//EN"
                  
                   "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
                  
                  <hibernate-configuration>
                  
                   <!-- a SessionFactory instance listed as /jndi/name -->
                   <session-factory>
                   <!-- este es datasource para correr con jboss -->
                   <property name="connection.datasource">java:/PampaDS</property>
                   <property name="show_sql">true</property>
                   <property name="use_outer_join">true</property>
                   <property name="dialect">
                   net.sf.hibernate.dialect.OracleDialect</property>
                   <property name="transaction.factory_class">
                   net.sf.hibernate.transaction.JTATransactionFactory</property>
                   <property name="hibernate.transaction.manager_lookup_class">
                   net.sf.hibernate.transaction.JBossTransactionManagerLookup</property>
                   <property name="hibernate.cglib.use_reflection_optimize">true</property>
                   <property name="hibernate.cache.use_query_cache">true</property>
                   <property name="hibernate.cache.provider_class">
                   net.sf.hibernate.cache.TreeCacheProvider</property>
                   <property name="hibernate.cache.region_prefix">ctacte</property>
                  
                  
                   <!-- mapping files -->
                  
                  
                   <mapping resource="gov/afip/pampa/component/supa/model/ICEntity.hbm.xml"/>
                   <mapping resource="gov/afip/pampa/component/supa/model/ImpuestoEntity.hbm.xml"/>
                   <mapping resource="gov/afip/pampa/component/supa/model/SubconceptoEntity.hbm.xml"/>
                   <mapping resource="gov/afip/pampa/component/supa/model/ConceptoEntity.hbm.xml"/>
                  
                   </session-factory>
                  
                  </hibernate-configuration>
                  



                  I want enable caching for any entities , but I not want for ICSentity .

                  Thanks.-

                  /Carlos