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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:37:51+00:00 2026-06-08T18:37:51+00:00

I have this issue with Hibernate that when i try to retrieve unique result

  • 0

I have this issue with Hibernate that when i try to retrieve unique result using criteria hibernate returns all the content from the table.

Session session = HibernateUtil.beginTransaction();
Customer c = new Customer();
c.setCustId(custId);
Example ex = Example.create(c);
Criteria criteria = HibernateUtil.getSession().createCriteria(Customer.class);
criteria.add(ex);

Customer customer = (Customer)criteria.uniqueResult();

HibernateUtil.commitTransaction();
HibernateUtil.closeSession();

However querying the table with:

Customer customer = (Customer)session
                    .createSQLQuery("select * from customer_ where custid = :id")
                    .addEntity(Customer.class)
                    .setInteger("id", custId)
                    .uniqueResult();

returns correct entry.
custId is the table’s primary key. And the Customer class contains 2 @OneToMany mappings.

Do I need to add something to the criteria example above??

  • 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-08T18:37:52+00:00Added an answer on June 8, 2026 at 6:37 pm

    The documentation says:

    Version properties, identifiers and associations are ignored.

    (emphasis mine)

    Why not simply using Session.get() if you have the identifier?

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

Sidebar

Related Questions

I have an issue trying to delete using hibernate. When I try to delete
I am learning Fluent NHibernate and this issue arose from that project. I have
I have this issue trying to get all the text nodes in an HTML
I have this issue: first, I execute a SQL query using Java and then
I have this issue with ComboBox that uses IEnumerable<Brush> as ItemsSource; the problem lies
I just have this issue with reading from a network stream in C#. Since
Heyy can somebody help me ? i have this issue that still do know
I have this exact issue ASP.net can’t update page from event handler and it's
I have searched all over for somebody else with this issue and found nothing...so
I have the same issue using hibernate against DB2 and MySQL. Here is 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.