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

  • SEARCH
  • Home
  • 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 7010569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:00:31+00:00 2026-05-27T22:00:31+00:00

I have an entity Book which holds a many-to-one relation with a Publisher. Here

  • 0

I have an entity Book which holds a many-to-one relation with a Publisher. Here is the hibernate mapping file for Book

<hibernate-mapping package="com.pramati.model">
    <class name="Book" table="BOOK">
        <id name="id" column="ID" type="long">
            <generator class="native"/>
        </id>
        <property name="name" column="NAME" type="string"/>
        <property name="isbn" type="int">
            <column name="ISBN" unique="true" not-null="true"/>
        </property>
        <property name="price" column="PRICE" type="double"/>
        <property name="bookIndex" column="BOOK_INDEX" type="int"/>
        <many-to-one name="publisher" class="Publisher" column="PUBLISHER_ID" cascade="save-update,delete"/>
    </class>
</hibernate-mapping>

Here is the native query I am using:

String sql = "SELECT {b.*}  FROM BOOK book LEFT OUTER JOIN PUBLISHER pub ON book.PUBLISHER_ID = pub.ID  WHERE book.price > 100 ";
Query query = session.createSQLQuery(sql).addEntity("b", Book.class);
List list = query.list();

On executing this, I am getting the following exception:

20:39:49,438 DEBUG SQL:401 - SELECT b.ID as ID0_0_, b.NAME as NAME0_0_, b.ISBN as ISBN0_0_, b.PRICE as PRICE0_0_, b.BOOK_INDEX as BOOK5_0_0_, b.PUBLISHER_ID as PUBLISHER6_0_0_ FROM BOOK book LEFT OUTER JOIN PUBLISHER pub ON book.PUBLISHER_ID = pub.ID WHERE book.price > 100 
20:39:49,466  WARN JDBCExceptionReporter:77 - SQL Error: 1054, SQLState: 42S22
20:39:49,467 ERROR JDBCExceptionReporter:78 - Unknown column 'b.ID' in 'field list'
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    at org.hibernate.loader.Loader.doList(Loader.java:2223)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
    at org.hibernate.loader.Loader.list(Loader.java:2099)
    at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
    at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
    at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
    at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
    at com.pramati.model.Publisher.main(Publisher.java:95)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'b.ID' in 'field list'
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

Why is this happening? If i just replace the alias as ‘book’ in addEntity and try fetching it using ‘select {book.*} ..’ (i.e. using the same alias name in SQL and in the addEntity method), it is working fine.

  • 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. Editorial Team
    Editorial Team
    2026-05-27T22:00:32+00:00Added an answer on May 27, 2026 at 10:00 pm

    You should be using {book.*}. Otherwise SQL driver don’t know what in the query it refers to.

    If you look at the caused by, you see that it’s the mysql driver that’s throwing the exception. Hibernate is duly replacing {b.*} with b.ID, ..., but the driver doesn’t know what in the FROM clause the fields map to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have an entity Entity1 that have one to many relation with Entity2 as
I have an Entity which holds a collection of OtherEntity in a many-to-many style
When I have a CoreData entity named, say, 'Book', which has a one-to-one relationship
I have a hierarchical data structure (using Entity beans)like say a Book Class which
context: I have an entity Book. A book can have one or more Descriptions.
I have a book entity which has a OneToMany relationship set up to Document
I have created a Entity Framework mapping based on the book Microsoft Entity Framework
If I have an entity that has an association (e.g. Book.Publisher), how do I
I have Entity Framework entities Events which have an EntityCollection of RSVP. I want
I have entity e.g. Product which aggregates other entities such as Category . Those

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.