Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 137051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:02:43+00:00 2026-05-11T07:02:43+00:00

I have the following class defined in my mapping XML file: <class name=com.data.StateRefData table=STATE_REF>

  • 0

I have the following class defined in my mapping XML file:

<class name='com.data.StateRefData' table='STATE_REF'>    <composite-id name='primaryKey' class='com.data.StateRefPkData'>        <key-property name='countryCode'>            <column name='COUNTRY_CODE'  />         </key-property>          <key-property name='state'>             <column name='STATE'  />         </key-property>     </composite-id>     <property name='dialingCode' column='DIALING_CODE'></property>    <property name='isActive' column='IS_ACTIVE'></property>    <property name='localeCode' column='LOCALE_CODE'></property>    <property name='stName' column='ST_NAME'></property> </class>  

I am trying to define a NameQuery for this class. What I tried was:

<query name='findState'>     <![CDATA[ from       com.data.StateRefData         WHERE primaryKey = :primaryKey     ]]>  </query>  

The Java code that I use to call this is:

Query stateQuery = null; List<StateRefData> stateList = null; StateRefPkData primaryKey = new StateRefPkData(); StateRefData filter = new StateRefData();  primaryKey.setCountryCode(inCountryCode); primaryKey.setState(inStateProvince); filter.setPrimaryKey(primaryKey);  stateQuery = session.getNamedQuery('findState'); stateQuery.setProperties(filter); 

However, I get these errors right at the ‘stateQuery.list()’ part:

[ERROR JDBCExceptionReporter:72] Line 1: Incorrect syntax near ','. org.hibernate.exception.SQLGrammarException: could not execute query          at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59)    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)    at org.hibernate.loader.Loader.doList(Loader.java:1596)    at org.hibernate.loader.Loader.list(Loader.java:1577)    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)  

Any idea on how to use a NamedQuery with a composite?

Note: I have also tried doing:

stateQuery.setParameter('primaryKey', primaryKey); 

and it still has the error.

New (edited): Here is the HQL and SQL that happens when I execute the code:

[DEBUG AST:223] --- HQL AST ---  \-[QUERY] 'query'     +-[SELECT_FROM] 'SELECT_FROM'     |  \-[FROM] 'from'     |     \-[RANGE] 'RANGE'     |        +-[DOT] '.'     |        |  +-[DOT] '.'     |        |  |  +-[DOT] '.'     |        |  |  |  +-[DOT] '.'     |        |  |  |  |  +-[IDENT] 'com'     |        |  |  \-[IDENT] 'data'     |        |  \-[IDENT] 'StateRefData'     |        \-[ALIAS] 'd'     \-[WHERE] 'WHERE'        \-[EQ] '='           +-[DOT] '.'           |  +-[IDENT] 'd'           |  \-[IDENT] 'primaryKey'           \-[COLON] ':'              \-[IDENT] 'primaryKey'  [DEBUG AST:193] --- SQL AST ---  \-[SELECT] QueryNode: 'SELECT'  querySpaces (STATE_REF)     +-[SELECT_CLAUSE] SelectClause: '{derived select clause}'     |  +-[SELECT_EXPR] SelectExpressionImpl: 'statere0_.COUNTRY_CODE as COUNTRY1_, statere0_.STATE as STATE' {FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=d,role=null,tableName=STATE_REF,tableAlias=statere0_,colums={,className=com.data.StateRefData}}}     |  \-[SQL_TOKEN] SqlFragment: 'statere0_.DIALING_CODE as DIALING3_60_, statere0_.IS_ACTIVE as IS4_60_, statere0_.LOCALE_CODE as LOCALE5_60_, statere0_.ST_NAME as ST6_60_'     +-[FROM] FromClause: 'from' FromClause{level=1, fromElementCounter=1, fromElements=1, fromElementByClassAlias=[d], fromElementByTableAlias=[statere0_], fromElementsByPath=[], collectionJoinFromElementsByPath=[], impliedElements=[]}     |  \-[FROM_FRAGMENT] FromElement: 'STATE_REF statere0_' FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=d,role=null,tableName=STATE_REF,tableAlias=statere0_,colums={,className=com.data.StateRefData}}     \-[WHERE] SqlNode: 'WHERE'        \-[EQ] SqlNode: '='           +-[DOT] DotNode: '(statere0_.COUNTRY_CODE, statere0_.STATE)' {propertyName=primaryKey,dereferenceType=2,propertyPath=primaryKey,path=d.primaryKey,tableAlias=statere0_,className=com.data.StateRefData,classAlias=d}           |  +-[ALIAS_REF] IdentNode: '(statere0_.COUNTRY_CODE, statere0_.STATE)' {alias=d, className=com.data.StateRefData, tableAlias=statere0_}           |  \-[IDENT] IdentNode: 'primaryKey' {originalText=primaryKey}           \-[NAMED_PARAM] SqlNode: '?'  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:02:44+00:00Added an answer on May 11, 2026 at 7:02 am

    Can you provide the SQL code that is being generated by turning on SQL logging?

    Here is a sample if you were using log4j.properties:

    log4j.logger.org.hibernate.SQL=DEBUG

    UPDATE #1

    I am not sure why the existing query does not work, but you should also give this a try. No need to update any other code as passing a POJO should automatically bind the getters to the named parameters.

    <query name='findState'>     <![CDATA[ from       com.data.StateRefData         WHERE primaryKey.countryCode = :countryCode AND primaryKey.state = :state     ]]> </query> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 300k
  • Answers 300k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer To have a multidimensional array, you'd need two levels of… May 13, 2026 at 7:59 pm
  • Editorial Team
    Editorial Team added an answer OK, I think I know what's going on... I looked… May 13, 2026 at 7:59 pm
  • Editorial Team
    Editorial Team added an answer I found out a way with using restictions (but by… May 13, 2026 at 7:59 pm

Related Questions

I am using struts 1.1 with tiles. I have tiles with definitions like <definition
I've just started playing with Guice, and a use-case I can think of is
I've decided to use Entity Framework for O/R Mapping, and DataAnnotations for validation in
I have a couple of tables that I want to map to classes. The

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.