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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:31:08+00:00 2026-05-31T02:31:08+00:00

I would like a Criteria query to instantiate a DTO class using an AliasToBeanResultTransformer.

  • 0

I would like a Criteria query to instantiate a DTO class using an AliasToBeanResultTransformer. The goal is to produce a light weight paged list with IDs for further action for a home page. This calls for a reporting type query.

            Criteria crit = session.createCriteria(Profile.class);

        crit.createAlias("personalData", "pd");
        crit.createAlias("emails", "e");
        crit.createAlias("telephones", "t");

        ProjectionList properties = Projections.projectionList();
        properties.add(Projections.property("id").as( "id"));
        properties.add(Projections.property("pd.lastName").as("lastName"));
        properties.add(Projections.property("pd.fullName").as("fullName"));
        properties.add(Projections.property("e.emailAddress").as("email"));
        properties.add(Projections.property("t.phoneNumber").as("phone"));

        crit.setProjection(properties);

        crit.setResultTransformer(new AliasToBeanResultTransformer(ProfileDTO.class));
        profiles = crit.list();

This fails to instantiate my DTO class. ProfileDTO has a matching constructor:

public ProfileDTO(Long id, String lastName, String fullName, String email,
        String phone) {
    this(id,fullName);
    this.lastName = lastName;
    this.email = email;
    this.phone = phone;
}

And the query works when I construct ProfileDTO objects manually with the result rows

        List<Object[]> rows = crit.list();

        for ( Object[] row: rows ) {
            ProfileDTO dto = new ProfileDTO();
            dto.setId((Long)row[0]);
            dto.setLastName((String)row[1]);
            dto.setFullName((String)row[2]);
            dto.setEmail((String)row[3]);
            dto.setPhone((String)row[4]);
            profiles.add(dto);
        }

My workaround is working fine, but it seems unnecessary. What am I doing wrong?

  • 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-31T02:31:10+00:00Added an answer on May 31, 2026 at 2:31 am

    The AliasToBeanResultTransformer uses setters to populate the DTO. If you want to use a constructor, to create your bean instance, you need to use an AliasToBeanConstructorResultTransformer.

    Your DTO seems to have a setter for all the elements of the tuple, except for lastName. Maybe this is the problem.

    That said, your code as is is simple, easy to maintain, and refactorable. It wouldn’t be refactorable with an AliasToBeanResultTransformer. I generally prefer to instantiate my DTOs myself, just as you did.

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

Sidebar

Related Questions

I'd like to do a subtraction of sets based on criteria. A pseudo-query would
I have a query created with Hibernate Criteria like this: Criteria criteria = db.getSession().createCriteria(Vendor.class);
I have an SQL query that I would like to convert into a criteria
I would like to use Date() function in hibernate criteria, since one field is
I would like recommendations for upload scripts/components. My criteria: No flash Plain Javascript ok,
I would like to save a queryset criteria to the DB for reuse. So,
I would like to write a query that simply returns 1 or 0 depending
I have a criteria query that I am using to show pages of results.
I have created a Hibernate (3.5) Criteria query: Criteria criteria = db.getSession().createCriteria(Vendor.class); criteria.add(Restrictions.isEmpty(models)); When
I would like to execute a LINQ query with a dynamic where clause depending

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.