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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:37:44+00:00 2026-06-16T08:37:44+00:00

I have an entity UserDetails which has the following variables: String userId String userName

  • 0

I have an entity “UserDetails” which has the following variables:

  1. String userId
  2. String userName
  3. UserContact userContact (where UserContact is an Embeddable class)

UserContact has the following variables:

  1. String phoneNumber
  2. String email
  3. String city

What will be a Hibernate Criteria for fetching the following list:

Users with userName = ‘sam’ and with city = ‘New York’

I tried the following and got the runtime exception that it doesn’t recognize the variable ‘city’:

List<UserLogin> list = session.createCriteria(UserLogin.class)
    .add(Restrictions.eq("userName","sam"))
    .add(Restrictions.eq("city", "New York"))
    .list();
  • 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-06-16T08:37:46+00:00Added an answer on June 16, 2026 at 8:37 am

    Oh I figured it out…

    List<UserLogin> list = session.createCriteria(UserLogin.class)
       .add(Restrictions.eq("userName","sam"))
       .add(Restrictions.eq("userContact.city", "New York"))
       .list();
    

    Silly, just needed to add ‘userContact.city’ instead of ‘city’, where userContact is the object of the class UserContact in my entity.

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

Sidebar

Related Questions

I have an entity class userdetails which has the username, userid (numeric) and password
I have a User class marked as entity which also implements UserDetails. I want
In my business model I have Entity class (IPoint interface ) that has a
I have entity called Customer and it has three properties: public class Customer {
suppose i have @Entity A, which has an eager @ManyToOne to @Entity B, and
I have entity A which has an IList of B called Bs and B
I have a entity which has a list of Child1 objects. The mappings seem
I have entity Ideas, which has child entity collection ChildIdeas. I need to load
I have the following database structure (which can't be changed): Users - UserID (int)
I have entity class which is used to model a weather station, and it

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.