Note that there are some explanatory texts on larger screens.

plurals
  1. POJPA root get in Hibernate not working with IdClass attribute
    text
    copied!<p>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.</p> <p>This bit of code worked fine in openJPA, but I've decided to make the move to hibernate for various reasons.</p> <p>The code that fails:</p> <pre><code>CriteriaBuilder queryBuilder = getEntityManager().getCriteriaBuilder(); CriteriaQuery&lt;Tuple&gt; query = queryBuilder.createTupleQuery(); Root&lt;ProductSearchFilter&gt; 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); </code></pre> <p>The error:</p> <pre><code>java.lang.IllegalArgumentException: Unable to resolve attribute [productId] against path </code></pre> <p>My Mapping setup:</p> <pre><code>@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; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload