Announcement Announcement Module
Collapse
No announcement yet.
Named query definition & configuration problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Named query definition & configuration problem

    Since I have a few complicated queries, I thought it would be better to use named query method and definite them outside of Java DAO class. Followed the sample application from the "Professional J2EE with Spring framework", I have those queries definited in the queries.hbm.xml file. For example, I have the following definition:

    <query name="getByTopic">
    <![CDATA[
    from Article ae left join Topic t
    where ae.id = t.entry
    and ae.status = 1
    and t.keynote = :topic
    order by ae.publishedDate desc
    ]]>
    </query>

    During the configuration, I get an error as:

    org.hibernate.hql.ast.QuerySyntaxError: Path expected for join! [

    from com.xxx.domain.Article ae left join Topic t
    where ae.id = t.entry
    and ae.status = 1
    and t.keynote = :topic
    order by ae.publishedDate desc

    ]

    Since I saw the full path is added into the Article class, I add the path to the Topic class. This time, the sessionFactory, which is configured with the hbm.xml file, can't initiated without much usefull information.

    What I am missing here?

    Thanks for your inputs in advance.

    v.

  • #2
    Turn on logging or post the logs (short as they are here) otherwise there is not much one can say.

    Comment


    • #3
      Here is the logging messages for the configuration after I made the change. As I had said, it doesn't say much thing useful. I don't know the log level can be turned up to see more information.

      org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext-hibernate.xml]: Initialization of bean failed; nested exception is org.hibernate.HibernateException: Errors in named queries: getBySubmitter, getByCategory, getAll, getByTopic
      org.hibernate.HibernateException: Errors in named queries: getBySubmitter, getByCategory, getAll, getByTopic
      at org.hibernate.impl.SessionFactoryImpl.<init>(Sessi onFactoryImpl.java:302)
      at org.hibernate.cfg.Configuration.buildSessionFactor y(Configuration.java:1005)
      at org.springframework.orm.hibernate3.LocalSessionFac toryBean.newSessionFactory(LocalSessionFactoryBean .java:746)
      at org.springframework.orm.hibernate3.LocalSessionFac toryBean.afterPropertiesSet(LocalSessionFactoryBea n.java:673)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:962)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:354)
      at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:223)
      at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:147)
      at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveReference(BeanDefinitio nValueResolver.java:176)
      at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveValueIfNecessary(BeanDe finitionValueResolver.java:105)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:916)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:727)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:336)
      at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:223)
      at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:147)
      at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveReference(BeanDefinitio nValueResolver.java:176)
      at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveValueIfNecessary(BeanDe finitionValueResolver.java:105)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:916)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:727)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:336)
      at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:223)
      at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:147)
      at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveReference(BeanDefinitio nValueResolver.java:176)
      at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveValueIfNecessary(BeanDe finitionValueResolver.java:105)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:916)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:727)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:336)
      at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:223)
      at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:147)
      at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:277)
      at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:312)
      at org.springframework.web.context.support.AbstractRe freshableWebApplicationContext.refresh(AbstractRef reshableWebApplicationContext.java:134)
      at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:230)
      at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:156)
      at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 48)
      at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:3669)
      at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4104)
      at org.apache.catalina.manager.ManagerServlet.start(M anagerServlet.java:1175)
      at org.apache.catalina.manager.HTMLManagerServlet.sta rt(HTMLManagerServlet.java:510)
      at org.apache.catalina.manager.HTMLManagerServlet.doG et(HTMLManagerServlet.java:104)
      at javax.servlet.http.HttpServlet.service(HttpServlet .java:689)
      at javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
      at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:213)
      at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:178)
      at org.apache.catalina.authenticator.AuthenticatorBas e.invoke(AuthenticatorBase.java:482)
      at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:105)
      at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:148)
      at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:856)
      at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConnection(Http11Protocol.jav a:744)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:527)
      at org.apache.tomcat.util.net.LeaderFollowerWorkerThr ead.runIt(LeaderFollowerWorkerThread.java:80)
      at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:684)
      at java.lang.Thread.run(Thread.java:595)

      Comment


      • #4
        Logging can be turned on to be more verbose through a configuration file. See the log4j and commons-logging websites (these are the libraries used by most apps including tomcat). You can find them on logging.apache.org and jakarta.apache.org.

        Comment


        • #5
          I don't get any more useful information after I turn up the log level on both org.hibernate.hql and org.springframework.orm.hibernate3. Instead of finding out the problem from the log message, I think it might be better to ask what is the right way.

          Comment


          • #6
            I would like to rephrase this problem.

            I have this queries.hbm.xml under the WEB-INF/class. And its format is as:

            <hibernate-mapping auto-import="true" package="com.zzz.domain">

            <query name="getByTopic">
            <![CDATA[
            from Article ae left join Topic t
            where ae.id = t.entry
            and ae.status = 1
            and t.keynote = :topic
            order by ae.publishedDate desc
            ]]>
            </query>
            ...

            </hibernate-mapping>

            All domain objects are definited in the domain directory. What else need to be done in order to get the join operation path right?

            Thanks again.

            Comment


            • #7
              Re: definition and conifiguration problem

              Hi,
              I am facing the same problem. I am getting
              org.hibernate.HibernateException: Errors in named queries: ListStockLevels, ListGuestInvitationsWithoutHostParty, GetCountryByCode, AllProviders, GetAccountByPortFolioPlan, LinkedDocumentTemplateNames, GetAccountByVirtualAgent, DequeuedJobsByDate, DequeuedJobs
              at org.hibernate.impl.SessionFactoryImpl.<init>(Sessi onFactoryImpl.java:338)
              at org.hibernate.cfg.Configuration.buildSessionFactor y(Configuration.java:1154)
              at org.springframework.orm.hibernate3.LocalSessionFac toryBean.newSessionFactory(LocalSessionFactoryBean .java:807)
              at org.springframework.orm.hibernate3.LocalSessionFac toryBean.buildSessionFactory(LocalSessionFactoryBe an.java:740)
              at org.springframework.orm.hibernate3.AbstractSession FactoryBean.afterPropertiesSet(AbstractSessionFact oryBean.java:131)
              at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1062)
              at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1029)
              ... 25 more

              I was wondering if you have found the solution to your problem and can post it here. Thanks.

              kind regards,
              Ravi

              Comment


              • #8
                Is it possible to see the hbm files for the queries that are failing validation?
                Last edited by karldmoore; Aug 30th, 2007, 06:46 AM.

                Comment


                • #9
                  re: definition &amp; configuration problem

                  Sure, here is one such hbm file.

                  <?xml version="1.0"?>
                  <!DOCTYPE hibernate-mapping PUBLIC
                  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

                  <hibernate-mapping package="com.mftl.gfas.fulfilment.business">
                  <class name="FulfilmentItemBO" table="FulfilmentItem">

                  <id type="com.mftl.gfas.type.MinusOneKey" name="itemId" column="ItemId">
                  <generator class="assigned"/>
                  </id>
                  <property name="itemName" column="ItemName" not-null="true"/>
                  <property name="status" column="StatusId" not-null="true"/>
                  <property name="includedIn" column="PackageId" not-null="false"/>
                  <property name="compliant" column="Compliance" not-null="true"/>
                  <property name="partCode" column="PartCode" not-null="true"/>
                  <property name="comment" column="Comment" not-null="false"/>
                  <property name="version" column="Version" not-null="true"/>
                  <many-to-one name="language" column="LanguageId" class="com.mftl.gfas.common.business.LanguageBO" not-null="false"/>
                  <!-- Mapping it to the FulfilmentCountryBO so that the values 0 (for 'All') can be taken care of -->
                  <!--<many-to-one name="country" column="CountryId" class="com.mftl.gfas.common.business.CountryBO" not-null="false"/>-->
                  <many-to-one name="country" column="CountryId" class="com.mftl.gfas.fulfilment.business.Fulfilmen tCountryBO" not-null="false"/>
                  <property name="maxOrderQuantity" column="MaxOrderQuantity" not-null="false"/>

                  <!-- this is done as some values like 0, 255 are inserted into Product Group column -->
                  <!-- property name="productGroupId" column="ProductGroupId" not-null="false" /-->
                  <!-- <many-to-one name="productGroup" column="ProductGroupId" class="com.mftl.gfas.common.business.ProductGroupB O" not-null="false"/>-->
                  <!-- Mapping it to the FulfilmentProductGroupBO so that the values 0 and 255 can be taken care of -->
                  <many-to-one name="productGroup" column="ProductGroupId" class="com.mftl.gfas.common.business.MarketingProd uctGroupBO" not-null="false"/>

                  <many-to-one name="fulfilmentType" column="TypeId" class="com.mftl.gfas.common.business.FulfilmentIte mTypeBO" not-null="true"/>

                  <bag name="fulfilmentItemStockGroups" cascade="all" lazy="true">
                  <key column="FulfilmentItemId"/>
                  <one-to-many class="FulfilmentItemStockGroupBO"/>
                  </bag>

                  <bag name="enclosures" table="PackageEnclosure" cascade="all" lazy="true">
                  <key column="PackageId"/>
                  <many-to-many class="com.mftl.gfas.fulfilment.business.Fulfilmen tItemBO" column="ItemId"/>
                  </bag>

                  <!--bag name="fulfilmentItemVersions" table="FulfilmentItemVersion" cascade="all" lazy="true">
                  <key column="parentItemId"/>
                  <many-to-many class="com.mftl.gfas.fulfilment.business.Fulfilmen tItemBO" column="ItemId"/>
                  </bag-->

                  <bag name="fulfilmentItemVersions" table="FulfilmentItemVersion" cascade="all" lazy="true">
                  <key column="parentItemId"/>
                  <one-to-many class="FulfilmentItemVersionBO"/>
                  </bag>

                  <!--bag name="fulfilmentItemVersions" table="FulfilmentItemVersion">
                  <key column="ItemId"/>
                  <one-to-many class="com.mftl.gfas.fulfilment.business.Fulfilmen tItemVersionBO"/>
                  <composite-element class="com.mftl.gfas.fulfilment.business.Fulfilmen tItemVersionBO">
                  <many-to-one name="childItem" class="com.mftl.gfas.fulfilment.business.Fulfilmen tItemBO" column="ItemId"/>
                  <property name="parentItemId" column="ParentItemId" not-null="true"/>
                  <property name="latest" column="IsLatest" not-null="true"/>
                  <property name="version" column="Version" not-null="true"/>
                  </composite-element>
                  </bag-->

                  <bag name="workGroups" table="WorkGroupItems" cascade="all" lazy="true">
                  <key column="ItemId"/>
                  <many-to-many class="com.mftl.gfas.common.business.WorkGroupBO" column="WorkGroupId"/>
                  </bag>

                  </class>

                  <query name="ListStockLevels"><![CDATA[
                  select new com.mftl.gfas.fulfilment.business.StockLevelBO(f, h)
                  from FulfilmentItemBO as f
                  join elements(f.workGroups) as g
                  left join elements(f.fulfilmentItemStockGroups) as h
                  where g.WorkGroupKey=:selectedWorkGroupId
                  and f.fulfilmentType.FulfilmentItemTypeId != :fulfilmentItemType_LETTER
                  and f.fulfilmentType.FulfilmentItemTypeId != :fulfilmentItemType_PACKAGE
                  and f.fulfilmentType.inHouse = 0
                  and f.status = :fulfilmentItemStatus_STATUS_READY
                  order by f.itemName, f.itemId
                  ] ]></query>

                  <query name="GetAllStock">
                  <![CDATA[
                  select new com.mftl.gfas.fulfilment.business.FulfilmentItemSt ockSummaryBO(
                  workgroup.name,
                  item.itemName,
                  stocklevel.physicalQuantity)
                  from FulfilmentItemBO as item
                  join elements(item.workGroups) as workgroup
                  join elements(item.fulfilmentItemStockGroups) as stocklevel
                  where workgroup.stockGroupId is not null
                  and stocklevel.stockGroup.id = workgroup.stockGroupId
                  and item.status = :fulfilmentItemStatus_STATUS_READY
                  order by item.status,
                  workgroup.name,
                  item.fulfilmentType.typeName,
                  item.itemName
                  ]]>
                  </query>

                  </hibernate-mapping>

                  Please let me know if you need any other info. Thanks.

                  kind regards,
                  Ravi

                  Comment


                  • #10
                    I would give Costins suggestion a try, up the logging to get some more information. It's hard to see what is going wrong here.
                    Last edited by karldmoore; Aug 30th, 2007, 06:45 AM.

                    Comment


                    • #11
                      Bug In Hibernate3 : SessionFactoryImpl

                      Originally posted by karldmoore View Post
                      I would give Costins suggestion a try, up the logging to get some more information. It's hard to see what is going wrong here.
                      Code:
                      private Map checkNamedQueries() throws HibernateException {
                      		Map errors = new HashMap();
                      
                      		// Check named HQL queries
                      		log.debug("Checking " + namedQueries.size() + " named HQL queries");
                      		Iterator itr = namedQueries.entrySet().iterator();
                      		while ( itr.hasNext() ) {
                      			final Map.Entry entry = ( Map.Entry ) itr.next();
                      			final String queryName = ( String ) entry.getKey();
                      			final NamedQueryDefinition qd = ( NamedQueryDefinition ) entry.getValue();
                      			// this will throw an error if there's something wrong.
                      			try {
                      				log.debug("Checking named query: " + queryName);
                      				//TODO: BUG! this currently fails for named queries for non-POJO entities
                      				queryPlanCache.getHQLQueryPlan( qd.getQueryString(), false, CollectionHelper.EMPTY_MAP );
                      			}
                      			catch ( QueryException e ) {
                      				errors.put( queryName, e );
                      			}
                      			catch ( MappingException e ) {
                      				errors.put( queryName, e );
                      			}
                      		}

                      There is a bug in the Hibernate 3 SessionFactoryImpl implemenation.
                      I got a bug in a NamedQuery. Are you referring to the same ?

                      Comment


                      • #12
                        I think this problem was actually referring to starting the application. Hibernate was actually complaining that there was a problem with the named queries. I didn't managed to replicate this locally however. What is the problem that you are having?
                        Last edited by karldmoore; Aug 30th, 2007, 06:45 AM.

                        Comment


                        • #13
                          Originally posted by karldmoore View Post
                          I think this problem was actually referring to starting the application. Hibernate was actually complaining that there was a problem with the named queries. I didn't managed to replicate this locally however. What is the problem that you are having?
                          'named queries for non-POJO entities' Means I have an annotated POJO like the following and it simply failed to execute.

                          Code:
                          @Entity
                          @Table(name = "employee")
                          @NamedNativeQuery(name = "findEmployeesInSalaryRange", query = "select e from employee as e where e.salary between :minSalary and :maxSalary")
                          public class Employee extends BaseObject {
                          
                          //properties
                          
                          }

                          If you refer to the above method (in my pervious message) Gavin acknowledges the same in the comment.

                          Comment


                          • #14
                            Originally posted by karldmoore View Post
                            I think this problem was actually referring to starting the application. Hibernate was actually complaining that there was a problem with the named queries. I didn't managed to replicate this locally however. What is the problem that you are having?
                            'named queries for non-POJO entities' Means I have an annotated POJO like the following and it simply failed to execute.

                            Code:
                            @Entity
                            @Table(name = "employee")
                            @NamedQuery(name = "findEmployeesInSalaryRange", query = "select e from employee as e where e.salary between :minSalary and :maxSalary")
                            public class Employee extends BaseObject {
                            
                            //properties
                            
                            }

                            Earlier query is a NamedQuery and not a NamedNativeQuery. Sorry for the mistake. This error came as I was experimenting whether NamedNativeQuery will work or not..


                            NB: NamedNativeQuery is not currently supported by hibernate, this also fails

                            Comment

                            Working...
                            X