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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:25:15+00:00 2026-05-26T20:25:15+00:00

in my user table i have two users when trying to select all users

  • 0

in my user table i have two users
when trying to select all users with HQL query as follows:

getCurrentSession().createQuery("From User").list();

it returns the two elements, and that’s right.

but when using createCriteria as follows:

getCurrentSession().createCriteria(User.class).list();

it returns 36 element (the two elements repeated)!!!!

any ideas why i am getting such behavior with createCriteria, is that related to hibernate relations ? because in User domain i have ManyToMany relation with Role domain, is it related to session factory or hibrenate version or hibernate configuration ?

relation:

@ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "user_role", joinColumns = { @JoinColumn(name = "user_id") }, inverseJoinColumns = { @JoinColumn(name = "role_id") })
    private Set<Role> roles = new HashSet<Role>(0);

i am confused, please advise, 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-26T20:25:16+00:00Added an answer on May 26, 2026 at 8:25 pm

    You have a Many-to-many relation with eager fetching. Criteria query will be translated into a SELECT with joins in it, and so in the result you’ll have many rows for each User.

    To remove duplicates add all the results to a HashSet, or use DistinctRootEntityResultTransformer.

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

Sidebar

Related Questions

I have two models, user and group. I also have a joining table groups_users.
I have a simple database with two tables. Users and Configurations. A user has
I have a User table that has all of their avatars saved in an
I have below query running on my users and chats table to join and
I have two tables -- an article table and a vote table. Users can
I have two tables from two different databases. For example: Table: Articles1 - Database:
I have a table with itemid|fieldid|value and i'm trying to setup a query that
I have two tables: events_archive and reports. The events table shows all information about
Basically, I have two tables, admin_privilege and admin_roll_privilege. I'm trying to write a query
I have a query against two databases that I'm trying to execute. The first

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.