You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@deltaspike.apache.org by Thomas Lustig <tm...@gmail.com> on 2018/05/20 13:41:49 UTC
Deltaspike data criteria support - Is it possible to query enum Sets?
dear community,
I really enjoy using the criteria api from the Deltaspike Data module.
At the moment i do have the problem, that I need to query an enumset.
The Class structure looks like this:
class BuildPart {
String name;
Set< Permission > permissions
}
class Permission {
Long userid;
Set<PermissionType> permissionTypes;
}
enum PermissionType {
CREATE, READ, EDIT, DELETE
}
i want to query for BuildParts where userid = 2 has permissions to read, I
tried:
------------ snippet start -----------
criteria()
.join(BuildPart_.permissions,
where (Permission.class)
.eq(Permission_.userid, 2L)
)
.join(Permission_.permissionTypes,
where(PermissionType.class)
.eq(PermissionType.READ) <--- NOT possible
)
------------ snippet end-----------
the "eq" function and also the "in" function always require a
"SingularAttribute" parameter.
when using Criteria of JPA, i got this simply working by:
------------ snippet start -----------
SetJoin<BuildPart, Permission> permissionJoin =
root.join(BuildPart_.permissions);
Predicate readPermissions = criteriaBuilder.and(
criteriaBuilder.equal(
permissionJoin.get(Permission_.userid),
2L,
criteriaBuilder.isMember(
PermissionType.READ,
permissionJoin.get(Permission_.permissionTypes)));
------------ snippet end-----------
Is there a way, how i could achieve such a query? (maybe with a workaround)
Thanking you very much for any idea
Tom