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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:08:50+00:00 2026-05-26T04:08:50+00:00

Hey I have a small problem doing a query: the query line is: Query

  • 0

Hey I have a small problem doing a query:
the query line is:
Query query = session.createQuery(“from Recipe r where r.name='” + searchString + “‘ and r.ownerid=” + userId );

the .hbm.xml file is:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                                   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Aug 26, 2011 10:56:44 AM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
 <class catalog="icdb" name="com.icdb.data.Recipe" table="recipes">
  <id name="recipeid" type="int">
   <column name="recipeid"/>
   <generator class="identity"/>
  </id>
  <many-to-one class="com.icdb.data.User" fetch="select" name="users">
   <column name="ownerid" not-null="true"/>
  </many-to-one>
  <property generated="never" lazy="false" name="releasedate" type="timestamp">
   <column length="19" name="releasedate" not-null="true"/>
  </property>
  <property generated="never" lazy="false" name="preparationtime" type="int">
   <column name="preparationtime" not-null="true"/>
  </property>
  <property generated="never" lazy="false" name="name" type="string">
   <column length="50" name="name" not-null="true"/>
  </property>
  <property generated="never" lazy="false" name="description" type="string">
   <column length="200" name="description"/>
  </property>
  <property generated="never" lazy="false" name="lastupdated" type="timestamp">
   <column length="19" name="lastupdated" not-null="true"/>
  </property>
  <property generated="never" lazy="false" name="servecount" type="java.lang.Integer">
   <column name="servecount"/>
  </property>
  <property generated="never" lazy="false" name="complete" type="boolean">
   <column name="complete" not-null="true"/>
  </property>
  <set fetch="select" inverse="true" lazy="true" name="recipepictureses"
   sort="unsorted" table="recipepictures">
   <key>
    <column name="recipeid" not-null="true"/>
   </key>
   <one-to-many class="com.icdb.data.RecipePicture"/>
  </set>
  <set fetch="select" inverse="true" lazy="true"
   name="recipeingredientses" sort="unsorted" table="recipeingredients">
   <key>
    <column name="recipeid" not-null="true"/>
   </key>
   <one-to-many class="com.icdb.data.RecipeIngredient"/>
  </set>
  <set fetch="select" inverse="true" lazy="true" name="recipetipses"
   sort="unsorted" table="recipetips">
   <key>
    <column name="recipeid" not-null="true"/>
   </key>
   <one-to-many class="com.icdb.data.RecipeTip"/>
  </set>
  <set fetch="select" inverse="true" lazy="true" name="recipereviewses"
   sort="unsorted" table="recipereviews">
   <key>
    <column name="recipeid" not-null="true"/>
   </key>
   <one-to-many class="com.icdb.data.RecipeReview"/>
  </set>
  <set fetch="select" inverse="true" lazy="true"
   name="recipeinstructionses" sort="unsorted" table="recipeinstructions">
   <key>
    <column name="recipeid" not-null="true"/>
   </key>
   <one-to-many class="com.icdb.data.RecipeInstruction"/>
  </set>
  <property name="recipedifficulty" type="int">
   <column name="recipedifficulty" not-null="true" sql-type="INTEGER"/>
  </property>
 </class>
</hibernate-mapping>

I get an exception – saying “Could not resolve property ownerid of Recipe …”

Why?
What have I declared wrong? Or do I do the query in a wrong way?

Yoav

  • 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-26T04:08:50+00:00Added an answer on May 26, 2026 at 4:08 am

    you either need to:

    1) add ownerid property to the mapping

    <property name="ownerid" type="int">
       <column name="ownerid" not-null="true"/>
    </property>
    

    OR

    2) use r.users.id in your query (assuming User’s primary key property is ‘id’)

    Query query = session.createQuery("from Recipe r where r.name='" + searchString + "' and r.users.id=" + userId );
    

    side-note 1:
    it’s better using positional or named parameters in a query instead of string concatenation – http://www.mkyong.com/hibernate/hibernate-parameter-binding-examples/

    side-note 2:
    as long as ‘users’ association mapping is many-to-one then the more proper name for it is ‘user’ – there is only one user associated with each recipe

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

Sidebar

Related Questions

Hey there, I have a small problem with compiling and linking with the command
hey I have a small problem with my rake class CreateEvents < ActiveRecord::Migration def
Hey guys, I have developed a small site that i would like to embed
Hey I have this code right here: http://pastie.org/534470 And on line 109 I get
Hey I have a problem comparing the value of a CGPoint (struct with two
hey guys i have written a small webservice which allows users of a company
Hey, I have a table with id, name, and weight columns. Weight is an
hey guys, i have very small issue please see the code below // this
Hey all, I have been away from rails for a while and have been
Hey guys, I have a very simple problem in MATLAB: I have some strings

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.