Results 1 to 10 of 14

Thread: Named query definition & configuration problem

Hybrid View

  1. #1

    Default 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. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Turn on logging or post the logs (short as they are here) otherwise there is not much one can say.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  3. #3

    Default

    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)

  4. #4
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    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.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  5. #5

    Default

    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.

  6. #6

    Default

    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.

  7. #7
    Join Date
    Feb 2007
    Posts
    2

    Default 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

  8. #8
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Is it possible to see the hbm files for the queries that are failing validation?
    Last edited by karldmoore; Aug 30th, 2007 at 06:46 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  9. #9
    Join Date
    Feb 2007
    Posts
    2

    Default re: definition & 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

  10. #10
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    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 at 06:45 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

Similar Threads

  1. ERROR: Context initialization failed
    By makhlo in forum Architecture
    Replies: 8
    Last Post: Jul 11th, 2008, 01:41 AM
  2. Problem With Hibernate 3 Named Query
    By duffymo in forum Data
    Replies: 4
    Last Post: May 26th, 2007, 03:25 PM
  3. hibernate pagination
    By oliverchua in forum Data
    Replies: 8
    Last Post: Sep 23rd, 2005, 06:06 PM
  4. Replies: 2
    Last Post: Sep 5th, 2004, 10:49 AM
  5. Replies: 5
    Last Post: Aug 27th, 2004, 07:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •