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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:55:58+00:00 2026-05-25T21:55:58+00:00

I’m trying to make a query using a wrapper class as result type. Sorry

  • 0

I’m trying to make a query using a wrapper class as result type. Sorry for the long post but I want to make my question as complete as possible.
The root class has 3 lists that I want to retrieve:

@Entity
@Table(name = "cash")
public final class Cash extends BaseSimpleModel {
    @Id
    @SequenceGenerator(name = "id", sequenceName = "cash_seq")
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "id")
    private Long cashID;

    @Column(length = 50, unique = true)
    private String description;

    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
    @JoinColumn(name = "cashID")
    private List<CashAllowedValue> allowedValueList;

    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
    @JoinColumn(name = "cashID")
    private List<CashAllowedCurrency> allowedCurrencyList;

    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
    @JoinColumn(name = "cashID")
    private List<CashAllowedCashier> allowedCashierList;
    ... getters and setters
}

Here is my wrapper class:

public class CashQueryResult extends QueryResult {
    private Long cashID;
    private String description;
    private List<CashAllowedValue> allowedValueList;
    private List<CashAllowedCurrency> allowedCurrencyList;
    private List<CashAllowedCashier> allowedCashierList;

    public CashQueryResult(Long id, String description, List<CashAllowedValue> allowedValueList, List<CashAllowedCurrency> allowedCurrencyList, List<CashAllowedCashier> allowedCashierList)
    {
        this.cashID = id;
        this.description = description;
        this.allowedValueList = allowedValueList;
        this.allowedCurrencyList = allowedCurrencyList;
        this.allowedCashierList = allowedCashierList;
    }
    ... getters
}

And here is my query:

public final List<CashQueryResult> getQRList(final CashQueryParameter cashQP, final QueryHint queryHint) {
    List<CashQueryResult> cashQRL = null;
    try {
        final CriteriaBuilder cb = em.getCriteriaBuilder();
        final PredicateBuilder pb = new PredicateBuilder(cb);
        final CriteriaQuery<CashQueryResult> cq = cb.createQuery(CashQueryResult.class);
        final Root<Cash> cash = cq.from(getModelClass());

        // Joins.
        final ListJoin<Cash, CashAllowedValue> allowedValueList = cash.join(Cash_.allowedValueList, JoinType.LEFT);
        final ListJoin<Cash, CashAllowedCurrency> allowedCurrencyList = cash.join(Cash_.allowedCurrencyList, JoinType.LEFT);
        final ListJoin<Cash, CashAllowedCashier> allowedCashierList = cash.join(Cash_.allowedCashierList, JoinType.LEFT);

        // Paths.
        final Path<ValueTypeEnum> valueType = allowedValueList.get(CashAllowedValue_.valueType);
        final Path<Currency> currency = allowedCurrencyList.get(CashAllowedCurrency_.currency);
        final Path<IntranetUser> intranetUser = allowedCashierList.get(CashAllowedCashier_.cashier);

        // Expressions. Just for testing purposes.
        final Expression<List<CashAllowedValue>> cashAllowedValueListExpression = cash.get(Cash_.allowedValueList);
        final Expression<List<CashAllowedCurrency>> cashAllowedCurrencyExpression = cash.get(Cash_.allowedCurrencyList);
        final Expression<List<CashAllowedCashier>> cashAllowedCashierExpression = cash.get(Cash_.allowedCashierList);

        cq.distinct(true);
        cq.select(cb.construct(CashQueryResult.class, cash.get(Cash_.cashID), cash.get(Cash_.description),
            // cash.get(Cash_.allowedValueList), cash.get(Cash_.allowedCurrencyList), cash.get(Cash_.allowedCashierList) // does not work
            // cashAllowedValueListExpression, cashAllowedCurrencyExpression, cashAllowedCashierExpression // does not work
            allowedValueList, allowedCurrencyList, allowedCashierList // does not work
        ));

        // cq.multiselect(cash.get(Cash_.cashID), cash.get(Cash_.description),
        //     allowedValueList, allowedCurrencyList, allowedCashierList
        // ); // does not work

        cq.where(cb.and(pb.like(cash.get(Cash_.description), cashQP.getDescription()), pb.equal(valueType, cashQP.getValueType()), pb.equal(currency.get(Currency_.currencyID), cashQP.getCurrencyID()), pb.equal(intranetUser.get(IntranetUser_.agentID), cashQP.getIntranetUserID())));
        cq.orderBy(cb.asc(cash.get(Cash_.description)));

        final TypedQuery<CashQueryResult> tq = em.createQuery(cq);
        tq.setFirstResult(queryHint.getFirstResult());
        tq.setMaxResults(queryHint.getMaxResults());
        cashQRL = tq.getResultList();
    }
    catch (Throwable t) {
        throw new EJBException(t.getMessage());
    }
    return cashQRL;
}

Finally, the exception (it varies depending on what select method I try but it’s always something like this):

2011-09-12 16:12:26,165 ERROR [org.hibernate.hql.PARSER] (http-127.0.0.1-8080-2) Unable to locate appropriate constructor on class [com.ebizlink.adonis.erp.model.support.CashQueryResult] [cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.ebizlink.adonis.erp.model.support.CashQueryResult]
2011-09-12 16:12:26,169 SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (http-127.0.0.1-8080-2) javax.ejb.EJBException: org.hibernate.hql.ast.QuerySyntaxException:
Unable to locate appropriate constructor on class [com.ebizlink.adonis.erp.model.support.CashQueryResult]
[select distinct new com.ebizlink.adonis.erp.model.support.CashQueryResult(generatedAlias0.cashID, generatedAlias0.description, generatedAlias1, generatedAlias2, generatedAlias3)
 from com.ebizlink.adonis.erp.model.Cash as generatedAlias0
    left join generatedAlias0.allowedValueList as generatedAlias1
    left join generatedAlias0.allowedCurrencyList as generatedAlias2
    left join generatedAlias0.allowedCashierList as generatedAlias3
 where ( 1=1 ) and ( 1=1 ) and ( 1=1 ) and ( 1=1 )
 order by generatedAlias0.description asc]

For reference, here is the PredicateBuilder just in case.
I searched the web but I couldn’t find somebody that is trying to retrieve many lists.
Am I missing something obvious? Multiple fetches are a no go (hibernate bug), and I can’t make the lists Eager either.

Another related question would be:
Can I make a query so, that the lists of my wrapper class are also entity wrappers and not entities? (For example: Instead of using Cashiers, just get first name and last name, and use a list of CashierWrapper which holds both strings)

I really thank you and I hope you can help me.

  • 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-25T21:55:59+00:00Added an answer on May 25, 2026 at 9:55 pm

    It is likely that you cannot do that, what specification says about arguments to constructor expression:

    constructor_expression ::= NEW constructor_name ( constructor_item {,constructor_item}* )
    constructor_item ::=
    single_valued_path_expression | scalar_expression | aggregate_expression | identification_variable

    And lists (collection_valued_field) you try to offer to constructor is not any of the constructor_item.

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want use html5's new tag to play a wav file (currently only supported

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.