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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:01:19+00:00 2026-06-02T18:01:19+00:00

I want to make a criteria query that has the same behaviour as the

  • 0

I want to make a criteria query that has the same behaviour as the following SQL query:

SELECT Count(*)
FROM Datagathering_respuestas, Datagathering
WHERE Datagathering.document = 4 AND Datagathering.id_datagathering = datagathering_respuestas.id_datagathering
GROUP BY respuesta;

it is all around the following class:

public class DataGathering {
    private int id;
    private Usuario user;
    private Date fecha;
    private int individual;
    private DataDocument document;
    private List<String> respuestas;

and it’s corresponding mapping file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <class name="pe.com.abf.pws.clases.DataGathering">
    <id column="id_datagathering" name="id">
      <generator class="identity"/>
    </id>
    <many-to-one class="pe.com.abf.pws.clases.DataDocument" name="document"/>
    <many-to-one class="pe.com.abf.pws.clases.Usuario" name="user"/>
    <property name="individual"/>
    <property name="fecha" type="timestamp"/>
    <list name="respuestas">
      <key column="id_datagathering"/>
      <index column="idx_respuesta"/>
      <element column="respuesta" length="4000" type="string"/>
    </list>
  </class>
</hibernate-mapping>

my main problem here is that the grouping property “respuestas” is defined as a list of element of type string and doesn’t have it’s own class. In SQL it’s easy to just reference to the corresponding table, but in Criteria, I have no idea how to reference to the elements to group by them. I have managed to get this query:

        Criteria c = s.createCriteria(DataGathering.class);
        c.add(Restrictions.eq("document.id", id));
        c.createCriteria("respuestas","resp");
        c.setProjection(Projections.projectionList().add(Projections.rowCount()));

which has the same behaviour as the above SQL query but without the group by element, so I think I am near. The problem is again that I don’t know how to refer to the values inside “respuestas”.

Any Idea how I can complete my query? any help will be highly appreciated.

  • 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-02T18:01:20+00:00Added an answer on June 2, 2026 at 6:01 pm

    I managed to do this by doing the following:

    da = s.createCriteria(DataGathering.class)
            .add(Restrictions.eq("document.id", id))
            .createCriteria("respuestas","resp")
            .setProjection(Projections.projectionList()
                    .add(Projections.groupProperty("resp.elements").as("resp"))
                    .add(Projections.count("resp.elements").as("amount")))
            .setResultTransformer(Transformers.aliasToBean(EncuestaHelper.class))
            .list();
    

    The trick is that Criteria uses the key "elements" to refer to a plain element collection. Then, giving the projections alias that match with the properties of an special class you can easily make a list of that class to use it on reports.

    Thanks to anyone who tried to help

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

Sidebar

Related Questions

I want to make this query on Symfony/Propel SELECT folders.NAME, COUNT(documents.NAME), COUNT(files.idfiles), SUM(files.size) FROM
I want to use criteria to make the following query. I have an Entity
I want make a bash script which returns the position of an element from
I have link for example domain.com/de/controler/action?param=value and I want make actionlink to keep same
I have a make table query that is used to run a report (due
I want to make it so that anytime the db is queried for an
I have a query that joins multiple tables. QString str1 = SELECT DISTINCT f.pk_file_ID,
I am trying to make a query in Codeigniter that will allow a user
I have the following acceptance criteria for creating a pdf file from my asp.net
I am trying to make a query with Hibernate criteria API. It looks simple

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.