Note that there are some explanatory texts on larger screens.

plurals
  1. POQuery Exception in Hibernate
    primarykey
    data
    text
    <p>I am using hibernate. I am using the given query to fetch information from db</p> <pre><code>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); </code></pre> <p>when i run this query I am getting this error</p> <pre><code> 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] </code></pre> <p>This is the menu.hbm.xml file</p> <pre><code>&lt;hibernate-mapping&gt; &lt;class name="com.hibernate.model.Menu" table="Menu" catalog="mydb"&gt; &lt;composite-id name="id" class="com.hibernate.model.MenuId"&gt; &lt;key-property name="menuId" type="int"&gt; &lt;column name="menu_id" /&gt; &lt;/key-property&gt; &lt;key-property name="restaurantId" type="long"&gt; &lt;column name="Restaurant_id" /&gt; &lt;/key-property&gt; &lt;key-property name="menuType" type="string"&gt; &lt;column name="menuType" length="45" /&gt; &lt;/key-property&gt; &lt;/composite-id&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>Menu Class</p> <pre><code>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; } } </code></pre> <p>MenuId Class</p> <pre><code>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()) &amp;&amp; (this.getRestaurantId() == castOther.getRestaurantId()) &amp;&amp; ((this.getMenuType() == castOther.getMenuType()) || (this .getMenuType() != null &amp;&amp; castOther.getMenuType() != null &amp;&amp; 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; } } </code></pre> <p>and this is my entry in the cfg file</p> <pre><code>&lt;mapping resource="com/hibernate/model/Menu.hbm.xml"/&gt; </code></pre> <p>How can I do this properly? Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload