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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:36:08+00:00 2026-06-15T12:36:08+00:00

So I have the following code DetachedCriteria subquery = DetachedCriteria.forClass(Component.class); subquery.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); subquery.createAlias(files, files); subquery.createAlias(files.review,

  • 0

So I have the following code

    DetachedCriteria subquery = DetachedCriteria.forClass(Component.class);
    subquery.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    subquery.createAlias("files", "files");
    subquery.createAlias("files.review", "review");
    subquery.createAlias("review.observers", "observer", Criteria.LEFT_JOIN);
    subquery.add(Restrictions.or(Restrictions.eq("review.owner", user), Restrictions.eq("observer.id", user.getId())));
    subquery.setProjection(Projections.groupProperty("review.id"));

    DetachedCriteria subquery2 = DetachedCriteria.forClass(ReviewNotification.class);
    subquery2.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    subquery2.add(Subqueries.propertyIn("review", subquery));
    subquery2.add(Restrictions.eq("reviewer", user));
    subquery2.setProjection(Projections.groupProperty("review"));

    Criteria criteria = session.createCriteria(Component.class);
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    criteria.createAlias("files", "files");
    criteria.createAlias("files.review", "review");
    criteria.add(Subqueries.propertyIn("review.id", subquery2));

now my problme is that if I do the following I get 2 as a return value (this is correct)

    List<Component> list = (List<Component>) criteria.list();
    for (Component reviewNotification : list) {
        System.out.println(reviewNotification);
    }
    return new Long(list.size());

but if I do

    criteria.setProjection(Projections.rowCount());
    return (Long) criteria.uniqueResult();

I get 4.

Anyone has any idea why the row count is failing?

I have just tried something else

    criteria.setProjection(Projections.countDistinct("id"));

and this also works. So does anyone have any idea what is happening? I guess the problem is comming from criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); an I wrong?

thanks for assistance

  • 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-15T12:36:10+00:00Added an answer on June 15, 2026 at 12:36 pm

    I seems that method setProjection overrides

    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    

    which would explain why return data is not unique

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

Sidebar

Related Questions

i have below code snippet in my legacy project DetachedCriteria subCriteria = DetachedCriteria.forClass(Employee.class); subCriteria.setProjection(Projections.distinct(Property.forName
I have following code in my template: <div class=account> {% if request.user.is_authenticated %} <a
I have following code in html: <div> <div style=float:left;margin:0.5em> <span class=title>Label1</span><br/> <input type=text name=name1
I have following code: class EntityBase (object) : __entity__ = None def __init__ (self)
I have following code - methods to read XML files. But it works very
I have following code: public abstract class TestProperty { public abstract Object PropertyValue {
I have following code in the html file: <div class=navbar navbar-fixed-top> <div class=navbar-inner> <div
I have following code for opening all files: int ret= open(zFile, flags, mode); posix_fadvise
I have following code in a html form <select name=category class=input onchange=ShowTB(this,'suggest');> <option value=0
I have following code: public abstract class Operand<T> { public T Value { get;

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.