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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:32:54+00:00 2026-06-08T10:32:54+00:00

My question is same exact issue like this SO question . Assume we have

  • 0

My question is same exact issue like this SO question.

Assume we have entity like

public class Employee {
    Long getId();
    String getName();
    Address getAddress();  
}

With the help of createCriteria and Projections we are trying to get id,name from users and city from address table.

The issue we are having is, city is not being set to address object city property.

Here is the code we tried:

 Criteria cr = session.createCriteria(Employee.class)
                    .setProjection(Projections.projectionList()
                    .add(Projections.property("id"), "id")
                    .add(Projections.property("Name"), "Name")
                    .add(Projections.property("address.city"), "address.city"))
                    .addOrder(Order.asc("address.city"))
                    .createAlias("address", "address")
                    .setResultTransformer(Transformers.aliasToBean(Employee.class));

Based on JBNizet comment on above question I understood that partially objects are bad idea, but If I am mandated to do that how can I achieve it? Any input would be 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-08T10:32:56+00:00Added an answer on June 8, 2026 at 10:32 am

    Use an AliasToBeanConstructorResultTransformer, and define a constructor like the following in your entity:

    public Employee(Long id, String name, String city) {
        this.id = id;
        this.name = name;
        this.address = new Address();
        this.address.setCity(city);
    }
    

    Or, (and this is my preferred solution, because it avoids reflection and allows refactoring the code with less risk) dont’t use any result transformer and construct your instances yourself:

    List<Object[]> rows = criteria.list();
    List<Employee> result = new ArrayList<Employee>(rows.size());
    for (Object[] row : rows) {
        Employee e = new Employee();
        e.setId((Long) row[0]);
        e.setName((String) row[1]);
        Address address = new Address();
        address.setCity((String) row[2]);
        e.setAddress(address);
        result.add(e);
    }    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Duplicate: This is the exact same question, from the exact same person, as Issue
I have almost the exact same question as at the following post (and I
This is driving me nuts. I believe I asked this exact same question, but
Basically my question is the exact same one as this: Simple client/server, TCP/IP encrypting
This is very similar to a previous question (and may be the exact same
I basically have the exact same problem as here: http://stackoverflow.com/questions/2416155/issue-in-executing-spring-web-project-in-eclipse-on-tomcat-server but the fix for
Since I posted this question, this issue has resolved itself. There must have been
My question looks like a classic one, but I cannot find the exact same
Someone has asked the exact same question in April, without any answer. But since
I have implement the exact same concept for my project- http://blog.perplexedlabs.com/2009/05/04/php-jquery-ajax-javascript-long-polling/ My question is,

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.