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 6908449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:33:53+00:00 2026-05-27T08:33:53+00:00

I am using hibernate. I am using the given query to fetch information from

  • 0

I am using hibernate. I am using the given query to fetch information from db

Query q = session.createQuery("select m.menuId,m.menuType,it.itemId,it.name,it.price,it.currency," +
        "ingr.ingredientId,ingr.ingredient from Menu as m, MenuItem as it," +
        "KeyIngredient as ingr where m.menuId  in "+
        "(select MenuId from MenuItem as itm innerjoin KeyIngredient as ing "+ 
        "where itm.itemId = ing.MenuItemId) and m.RestaurantId=" +restaurantId);

when i run this query I am getting this error

    could not resolve property: menuId of: com.hibernate.model.Menu [select m.menuId,m.menuType,it.itemId,it.name,it.price,it.currency,ingr.ingredientId,ingr.ingredient 
from com.hibernate.model.Menu as m, com.hibernate.model.MenuItem as it,com.hibernate.model.KeyIngredient as ingr where m.menuId  in (select MenuId from 
com.hibernate.model.MenuItem as itm innerjoin KeyIngredient as ing where itm.itemId = 
ing.MenuItemId) and m.RestaurantId=1]

This is the menu.hbm.xml file

<hibernate-mapping>
        <class name="com.hibernate.model.Menu" table="Menu" catalog="mydb">
            <composite-id name="id" class="com.hibernate.model.MenuId">
                <key-property name="menuId" type="int">
                    <column name="menu_id" />
                </key-property>
                <key-property name="restaurantId" type="long">
                    <column name="Restaurant_id" />
                </key-property>
                <key-property name="menuType" type="string">
                    <column name="menuType" length="45" />
                </key-property>
            </composite-id>
        </class>
    </hibernate-mapping>

Menu Class

public class Menu implements java.io.Serializable {

    private MenuId id;

    public Menu() {
    }

    public Menu(MenuId id) {
        this.id = id;
    }

    public MenuId getId() {
        return this.id;
    }

    public void setId(MenuId id) {
        this.id = id;
    }

}

MenuId Class

public class MenuId implements java.io.Serializable {

    private int menuId;
    private long restaurantId;
    private String menuType;

    public MenuId() {
    }

    public MenuId(int menuId, long restaurantId, String menuType) {
        this.menuId = menuId;
        this.restaurantId = restaurantId;
        this.menuType = menuType;
    }

    public int getMenuId() {
        return this.menuId;
    }

    public void setMenuId(int menuId) {
        this.menuId = menuId;
    }

    public long getRestaurantId() {
        return this.restaurantId;
    }

    public void setRestaurantId(long restaurantId) {
        this.restaurantId = restaurantId;
    }

    public String getMenuType() {
        return this.menuType;
    }

    public void setMenuType(String menuType) {
        this.menuType = menuType;
    }

    public boolean equals(Object other) {
        if ((this == other))
            return true;
        if ((other == null))
            return false;
        if (!(other instanceof MenuId))
            return false;
        MenuId castOther = (MenuId) other;

        return (this.getMenuId() == castOther.getMenuId())
                && (this.getRestaurantId() == castOther.getRestaurantId())
                && ((this.getMenuType() == castOther.getMenuType()) || (this
                        .getMenuType() != null
                        && castOther.getMenuType() != null && this
                        .getMenuType().equals(castOther.getMenuType())));
    }

    public int hashCode() {
        int result = 17;

        result = 37 * result + this.getMenuId();
        result = 37 * result + (int) this.getRestaurantId();
        result = 37 * result
                + (getMenuType() == null ? 0 : this.getMenuType().hashCode());
        return result;
    }

}

and this is my entry in the cfg file

<mapping resource="com/hibernate/model/Menu.hbm.xml"/>

How can I do this properly?
Thanks

  • 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-27T08:33:54+00:00Added an answer on May 27, 2026 at 8:33 am

    That query looks like SQL rather than HQL. If that’s the case, use session.createSQLQuery() instead:

    Query q = session.createSQLQuery("your SQL here");
    

    If I’m wrong and it’s meant to be HQL, you’ll need to post your mappings – it menu_id mapped as property?

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

Sidebar

Related Questions

I would like to query using hibernate given a particulay query string I did
When I run this query : select emp.emp_name as name from emp order by
To retrieve data from database using Hibernate, I use the following syntax : Query
when using hibernate with spring, can someone explain how the session unit of work
When using Hibernate 2nd level cache and query cache and not specifying anything inside
Whats wrong with the following JPA query select count(obj) from User as obj join
Given the following HQL Query: FROM Foo WHERE Id = :id AND Bar IN
i have spring project under java, using hibernate query, i like to use pessimistic
I have a web service that provides queries functionality using hibernate. A query can
Using Hibernate 's Criteria API , I want to select the record within a

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.