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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:55:13+00:00 2026-05-26T01:55:13+00:00

I’m trying to do a multiselect on an entity with an IdClass. I can’t

  • 0

I’m trying to do a multiselect on an entity with an IdClass. I can’t get a column that is mapped as part of the ID. It’s clear why I can’t, as none of the columns that are marked as @Ids are a part of the attributes in the EntityType that hibernate is creating, they are a part of the IdAttributes map.

This bit of code worked fine in openJPA, but I’ve decided to make the move to hibernate for various reasons.

The code that fails:

CriteriaBuilder queryBuilder = getEntityManager().getCriteriaBuilder();
CriteriaQuery<Tuple> query = queryBuilder.createTupleQuery();
Root<ProductSearchFilter> productSearchFilterRoot = query.from(ProductSearchFilter.class);
query.multiselect(productSearchFilterRoot.get("productId").alias("productId"),
            productSearchFilterRoot.get("category").alias("category"),
            productSearchFilterRoot.get("name").alias("name"),
            productSearchFilterRoot.get("fdaStatus").alias("fdaStatus"));
    query.distinct(true);

The error:

java.lang.IllegalArgumentException: Unable to resolve attribute [productId] against path

My Mapping setup:

@Table(name = "PRODUCT_SEARCH_FILTER")
@Entity()
@IdClass(ProductSearchFilterPK.class)
public class ProductSearchFilter {

private String source;
private String productId;
private String name;
private String category;
private String searchColumn;
private String fdaStatus;

@Column(name = "SOURCE", length = 11)
public String getSource() {
    return source;
}

public void setSource(String source) {
    this.source = source;
}

@Column(name = "PRODUCT_ID", length = 46, insertable = false, updatable = false)
@Id
public String getProductId() {
    return productId;
}

public void setProductId(String productId) {
    this.productId = productId;
}

@Column(name = "NAME", length = 510)
public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

@Column(name = "CATEGORY", length = 10)
public String getCategory() {
    return category;
}

public void setCategory(String category) {
    this.category = category;
}


@Column(name = "SEARCH_COLUMN", length = 1088, insertable = false, updatable = false)
@Id
public String getSearchColumn() {
    return searchColumn;
}

public void setSearchColumn(String searchColumn) {
    this.searchColumn = searchColumn;
}

@Column(name = "FDA_STATUS", insertable = false, updatable = false)
@Id
public String getFdaStatus() {
    return fdaStatus;
}

public void setFdaStatus(String fdaStatus) {
    this.fdaStatus = fdaStatus;
}
}



public class ProductSearchFilterPK implements Serializable {
private String productId;
private String searchColumn;
private String fdaStatus;

public String getFdaStatus() {
    return fdaStatus;
}

public void setFdaStatus(String fdaStatus) {
    this.fdaStatus = fdaStatus;
}

public String getProductId() {
    return productId;
}

public void setProductId(String productId) {
    this.productId = productId;
}

public String getSearchColumn() {
    return searchColumn;
}

public void setSearchColumn(String searchColumn) {
    this.searchColumn = searchColumn;
}
}
  • 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-26T01:55:13+00:00Added an answer on May 26, 2026 at 1:55 am

    There is workaround, which is using canonical metamodel.

    Unfortunately EntityModel we get from productSearchFilterRoot does not help us much, because it
    only gives us view as a set. So we cannot query Attributes of IdClass right away by name of attribute from there.
    But there they are anyway:

    //following will contain three attributes that are part of id.
    Set<SingularAttribute<? super ProductSearchFilter, ?>> s = model.getIdClassAttributes();
    

    Instead we we will go for canonical metamodel. For that we need one new class which we can implement
    by ourselves, or let Hibenate do it:

    @StaticMetamodel(ProductSearchFilter.class)
    public abstract class ProductSearchFilter_ {
        public static volatile SingularAttribute<ProductSearchFilter, String> category;
        public static volatile SingularAttribute<ProductSearchFilter, String> fdaStatus;
        public static volatile SingularAttribute<ProductSearchFilter, String> source;
        public static volatile SingularAttribute<ProductSearchFilter, String> name;
        public static volatile SingularAttribute<ProductSearchFilter, String> searchColumn;
        public static volatile SingularAttribute<ProductSearchFilter, String> productId;
    }
    

    And then we will use fields of ProductSearchFilter_ as argument to get in productSearchFilterRoot:

    CriteriaBuilder queryBuilder = getEntityManager().getCriteriaBuilder();
    CriteriaQuery<Tuple> query = queryBuilder.createTupleQuery();
    Root<ProductSearchFilter> productSearchFilterRoot = query.from(ProductSearchFilter.class);
    query.multiselect(
        productSearchFilterRoot.get(ProductSearchFilter_.productId).alias("productId"),
        productSearchFilterRoot.get(ProductSearchFilter_.category).alias("category"),
        productSearchFilterRoot.get(ProductSearchFilter_.name).alias("name"),
        productSearchFilterRoot.get(ProductSearchFilter_.fdaStatus).alias("fdaStatus"));
    query.distinct(true);
    

    Because we now have metamodel, I used it also to create selection for name, but because that one is not part of id, we could have left it as it was:

    productSearchFilterRoot.get("name").alias("name"),
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
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
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

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.