5 Replies Latest reply on Feb 9, 2009 5:57 PM by elenctic87

    Error creating sessionfactory when using HQL Editor

    elenctic87

      My project and all queries run fine when deployed to the server, but for some reason the exception below is thrown in the HQL editor. Do you know how to get rid of this so I can use the HQL editor again? This HQL editor used to work before I enabled query caching. (see persistence.xml below). Now, even if I disable query caching and restore persistence.xml to the way it was before, the HQL Editor still throws this exception. I have also tried explicitly enabling the second-level cache in persistence.xml to no avail.

      I have seen forum posts on this subject from as long ago as 2 years. There was not a clear resolution, so I am posting again. It seems like a class loading issue, but I have no idea how to fix it. I think I am posting this in the right forum, but if not, please kindly direct me to the appropriate place. Thank you.

      Exception: (Title: "Problems while creating sessionfactory")

      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.UpdateTimestampsCache.<init>(UpdateTimestampsCache.java:42)
       at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:337)
       at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
       at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
       at org.hibernate.console.ConsoleConfiguration$3.execute(ConsoleConfiguration.java:399)
       at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:64)
       at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:93)
       at org.hibernate.console.ConsoleConfiguration.buildSessionFactory(ConsoleConfiguration.java:394)
       at org.hibernate.eclipse.console.workbench.LazySessionFactoryAdapter.getChildren(LazySessionFactoryAdapter.java:43)
       at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.getChildren(BasicWorkbenchAdapter.java:99)
       at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.fetchDeferredChildren(BasicWorkbenchAdapter.java:105)
       at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:234)
       at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
      



      Persistence.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <!-- Persistence deployment descriptor for dev profile -->
      <persistence xmlns="http://java.sun.com/xml/ns/persistence"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
       version="1.0">
      
       <persistence-unit name="a1">
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/a1Datasource</jta-data-source>
       <properties>
       <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/>
       <property name="hibernate.hbm2ddl.auto" value="update"/>
       <property name="hibernate.show_sql" value="true"/>
       <property name="hibernate.format_sql" value="true"/>
       <property name="hibernate.cache.use_query_cache" value="true"/>
       <property name="jboss.entity.manager.factory.jndi.name" value="java:/a1EntityManagerFactory"/>
       </properties>
       </persistence-unit>
      
      </persistence>
      
      


        • 1. Re: Error creating sessionfactory when using HQL Editor
          maxandersen

          and if you set hibernate.cache.use_second_level_cache=true ?

          • 2. Re: Error creating sessionfactory when using HQL Editor
            elenctic87

            Yes, I tried that. I mentioned that at the top of my post: "I have also tried explicitly enabling the second-level cache in persistence.xml to no avail." This problem has been really tough to fix.

            • 3. Re: Error creating sessionfactory when using HQL Editor
              maxandersen

              hmm...and what if you set both querycache and 2nd lvl cache to true and *restart* eclipse - does that make a difference for you ?

              (note, I know this issue but I have not been able to reproduce it in a long time after fixing a bug around it in hibernate)

              Alternatively try and set the two options in a seperate .properties file in the console config.

              If neither helps please open a bug with the minimal project setup that causes this issue for you so we can reproduce - thanks!

              • 4. Re: Error creating sessionfactory when using HQL Editor
                elenctic87

                Ok, I have tried all combinations of the two cache settings in both the .properties file and persistence.xml. I will have to open a bug tomorrow, as I am about to leave the office today.

                • 5. Re: Error creating sessionfactory when using HQL Editor
                  elenctic87

                  I am pushing to get my current phase of development done, so I have not gotten to file a bug in Jira yet. But I have some new information that may help you reproduce the bug. After upgrading to the latest version of Tools, I created a new Seam project, and generated my entities from the database. I went to HQL editor, and queries ran successfully. I then enabled query cache in properties.xml, and that is when I saw the sessionfactory error again. Setting hibernate.cache.use_query_cache="false" caused the error to go away. So I'm pretty sure the problem is a conflict with query_cache being enabled. Does that help you diagnose the problem?