I’m using JPA2 as MySQL connector and use query builder to costruct queries. While trying to sort result list by entity parameter I’ve found some error:
SEVERE: java.lang.IllegalArgumentException: The attribute [customer}] from the managed type [EntityTypeImpl@1572996478:Documentation [ javaType: class pl.ego.software.entity.Documentation descriptor: RelationalDescriptor(pl.ego.software.entity.Documentation --> [DatabaseTable(documentation)]), mappings: 20]] is not present.
I’m not sure why but this is the only entity parameter which is not present in whole entity. This exception is raised when trying to use get method from class Root.
Root<Documentation> u = select.from(Documentation.class);
CriteriaBuilder builder = em.getCriteriaBuilder();
if (sortField != null) {
Order o;
if (sortOrder == SortOrder.ASCENDING) {
o = builder.asc(u.get(sortField));
} else {
o = builder.desc(u.get(sortField));
}
select.orderBy(o);
}
When sortField value is set to “customer” u.get(sortField) raise Exception mentioned above. If sortField is set to some different value everything works great.
Here is part of entity code to make sure that parameter exists.
@Size(max = 150)
@Column(name = "customer")
private String customer;
Not exactly but your post gave me some clue. Basically yes, exception was raised because of “}” sign at the end of field name but didn’t know why until now 🙂 I had some issue with
There was white space at the end.
Removing it fixed whole thing 😉