7 Replies Latest reply on Mar 11, 2010 10:18 AM by Sanjeev Verma

    Hibernate Archive Deployment in JBoss 5.1

    Sanjeev Verma Newbie

      I am trying to deploy a hibernate archive in a JBoss 5 installation. After facing a number of challenges, I think I am really close and just have one last hurdle - how do I get JBoss to recognise my persistent entities? I am using annotations to define my entities, and not *.hmb.xml files. Can anyone tell me if JBoss 5 can deploy a hibernate archive that is using annotations? I have attached the archive file alongwith source code just in case that helps.

       

      My *-hibernate.xml file looks like this:


      <hibernate-configuration xmlns="urn:jboss:hibernate-deployer:1.0">
         <session-factory name="java:/hibernate/Deals/SessionFactory" bean="jboss.test.har:service=Hibernate,testcase=TimersUnitTestCase">
            <property name="datasourceName">java:/DealsDS</property>
            <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
      <!--      <property name="sessionFactoryInterceptor">org.jboss.test.hibernate.SimpleInterceptor</property> -->
      <!--      <property name="ShowSqlEnabled">create</property> -->
            <depends>jboss:service=Naming</depends>
            <depends>jboss:service=TransactionManager</depends>
         </session-factory>
      </hibernate-configuration>


      One of my entity classes (as an exmaple) looks like this:


      package com.sanjeev.deals.entities;
      import java.io.Serializable;import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.GeneratedValue;
      import javax.persistence.GenerationType;
      import javax.persistence.Id;
      import javax.persistence.Table;


      @Entity
      @Table(name = "FEED_URLS")
      public class DataFeedURLInfo implements Serializable {
          @Id
          @GeneratedValue(strategy = GenerationType.IDENTITY)
          private Long id;


          @Column(name = "RETAILER_NAME")
          private String retailerName;


          @Column(name = "FEED_URL", nullable = false, unique = true)
          private String feedUrl;


          @Column(name = "FEED_CATEGORY")
          private String feedCategory;


          @Column(name = "FEED_SUBCATEGORY")
          private String feedSubcategory;
         
          @Column(name = "FEED_TIME_IN_MINUTES")
          private Integer minutes;


          /**
           * @return the id
           */
          public Long getId() {
              return id;
          }


          /**
           * @return the retailerName
           */
          public String getRetailerName() {
              return retailerName;
          }


          /**
           * @return the feedUrl
           */
          public String getFeedUrl() {
              return feedUrl;
          }


          /**
           * @return the feedCategory
           */
          public String getFeedCategory() {
              return feedCategory;
          }


          /**
           * @return the feedSubcategory
           */
          public String getFeedSubcategory() {
              return feedSubcategory;
          }


          /**
           * @return the minutes
           */
          public Integer getMinutes() {
              return minutes;
          }


          /**
           * @param minutes the minutes to set
           */
          public void setMinutes(Integer minutes) {
              this.minutes = minutes;
          }
      }

      This is the exception I see when I try to invoke any persistent class:

      javax.ejb.EJBException: org.hibernate.hql.ast.QuerySyntaxException: DataFeedURLInfo is not mapped [from DataFeedURLInfo where minutes >= :lowerLimit and minutes < :upperLimit]
          at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:77)
          at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
          at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:190)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
          at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
          at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:80)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
          at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
          at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
          at org.jboss.ejb3.mdb.MessagingContainer.localInvoke(MessagingContainer.java:282)
          at org.jboss.ejb3.mdb.MessagingContainer.localInvoke(MessagingContainer.java:270)
          at org.jboss.ejb3.mdb.MessagingContainer.callTimeout(MessagingContainer.java:308)
          at org.jboss.as.ejb3.timerservice.TimedObjectInvokerBridge.callTimeout(TimedObjectInvokerBridge.java:44)
          at org.jboss.ejb.txtimer.TimerImpl$TimerTaskImpl.run(TimerImpl.java:561)
          at java.util.TimerThread.mainLoop(Timer.java:512)
          at java.util.TimerThread.run(Timer.java:462)
      Caused by: org.hibernate.hql.ast.QuerySyntaxException: DataFeedURLInfo is not mapped [from DataFeedURLInfo where minutes >= :lowerLimit and minutes < :upperLimit]
          at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:181)
          at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110)
          at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:93)
          at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:277)
          at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)
          at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)
          at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
          at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
          at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
          at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
          at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:251)
          at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
          at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:134)
          at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
          at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
          at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94)
          at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
          at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
          at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1650)
          at com.sanjeev.deals.entities.dao.DataFeedURLInfoDAO.getDataFeedURLByTime(DataFeedURLInfoDAO.java:24)
          at com.sanjeev.deals.parser.mdb.GetAllDeals.processFeed(GetAllDeals.java:122)
          at com.sanjeev.deals.parser.mdb.GetAllDeals.processFeed(GetAllDeals.java:94)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:597)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:122)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111)
          at org.jboss.ejb3.EJBContainerInvocationWrapper.invokeNext(EJBContainerInvocationWrapper.java:69)
          at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.invoke(InterceptorSequencer.java:73)
          at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.aroundInvoke(InterceptorSequencer.java:59)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:597)
          at org.jboss.aop.advice.PerJoinpointAdvice.invoke(PerJoinpointAdvice.java:174)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
          at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.fillMethod(InvocationContextInterceptor.java:72)
          at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_fillMethod_16419067.invoke(InvocationContextInterceptor_z_fillMethod_16419067.java)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
          at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.setup(InvocationContextInterceptor.java:88)
          at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_setup_16419067.invoke(InvocationContextInterceptor_z_setup_16419067.java)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
          at org.jboss.ejb3.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:62)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
          at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:56)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
          at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
          at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
          at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:68)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
          at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
          ... 17 more

        • 1. Re: Hibernate Archive Deployment in JBoss 5
          Sanjeev Verma Newbie

          Also, I have tried introducing the <mapping/> element in the *-hibernate.xml file, but that did not help:

           

                <mapping class="com.sanjeev.deals.entities.Item"/>
                <mapping class="com.sanjeev.deals.entities.RetailerItemInfo"/>
                <mapping class="com.sanjeev.deals.entities.DataFeedURLInfo"/>

           

          The file does not like the grammar.

           

          Any help will be very appreciated!

          • 3. Re: Hibernate Archive Deployment in JBoss 5.1
            Sanjeev Verma Newbie

            After reading more about this error message, i tried out some of the suggestions, namely making sure my persistent classname is being spelled correctly in the hql, case matches etc. All of that is ok. I also tried replacing the classname with the fully qualified classname, that is com.sanjeev.deals.entities.DataFeedURLInfo, and with this, i get another "WARN" message, basically saying the same thing:

             

            WARN  [org.hibernate.hql.QuerySplitter] (EJB-Timer-1268197846438[target=jboss.j2ee:ear=deals.ear,jar=deals.jar,name=GetAllDeals,service=EJB3]) no persistent classes found for query class: from com.sanjeev.deals.entities.DataFeedURLInfo d

             

            So no progress :-(...Gurus, please help!!!

            • 4. Re: Hibernate Archive Deployment in JBoss 5.1
              jaikiran pai Master

              I persoanlly haven't tried HAR deployment in AS-5 (or for that matter, in any other version of AS). Any reason why you want to deploy it as a .har instead of a jar file as per the JPA spec?

               

              P.S: I do know that the JBoss In Action book covers an example of HAR deployments in AS-5 and it works. So you might want to take a look at that and see if you can spot the problem in your deployment.

              • 5. Re: Hibernate Archive Deployment in JBoss 5.1
                Sanjeev Verma Newbie

                Any reason why you want to deploy it as a .har instead of a jar file as per the JPA spec?

                Nope, I was just under the impression that deploying it as a .har will allow me to use all the hibernate specific features. But I think i am wrong there. That is what i will try next if this does not work in a couple of day :-(.

                 

                P.S: I do know that the JBoss In Action book covers an example of HAR deployments in AS-5 and it works. So you might want to take a look at that and see if you can spot the problem in your deployment.

                The example is using *.hbm.xml file to specify the object to database mapping, while i am using annotations. That is the difference.

                • 6. Re: Hibernate Archive Deployment in JBoss 5.1
                  Prat Gupta Newbie

                  I am trying to do the same thing, where i had a HAR deployed in Jboss 4.0 a while back and now i want to upgrade this to JBoss 5 and deploy the same way.

                   

                  I guess one reason could be that i want my application pieces already written using hibernate 2 inside of EJB 2.0 to work without having to go through the Hibernate entitymanager.

                   

                  But, when I switch to the new hibernate xml deployer configuration meaning jboss-hibernate.xml

                   

                  <?xml version="1.0" encoding="UTF-8"?>
                  <hibernate-configuration xmlns="urn:jboss:hibernate-deployer:1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                           xsi:schemaLocation="urn:jboss:hibernate-deployer:1.0 ">

                      <!-- a SessionFactory instance listed as /jndi/name -->
                      <session-factory  name="java:hibernate/SessionFactory">

                          <!--
                                  <depends>jboss:service=Naming</depends>
                                  <depends>jboss:service=TransactionManager</depends>
                          -->

                          <!-- properties -->
                          <property name="datasourceName">java:/@ds</property>
                          <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
                          <property name="showSqlEnabled">false</property>
                  <!--
                          <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
                          <property name="transactionManagerLookupStrategy">org.hibernate.transaction.JBossTransactionManagerLookup</property>
                  -->

                      </session-factory>

                  </hibernate-configuration>

                   

                   

                  It fails when i try to specify the transaction properties.

                   

                  Any success that anybody had with this and any guidance on approach

                   

                  Prat

                  BURSYS

                  • 7. Re: Hibernate Archive Deployment in JBoss 5.1
                    Sanjeev Verma Newbie

                    Ok, so I deployed the entities as standard JPA entities, and now it works like a charm. Took me all of 15 minutes to write up the persistence.xml, and the cool thing is, I can inject into my MDBs a Hibernate SessionFactory using the standard @PersistenceUnit JPA annotation, cause JBoss takes care of the conversion under the covers. this way I did not have to change a single line of code! Great!

                     

                    Thanks for the help Jaikiran, you rock!

                    1 of 1 people found this helpful