Fix errors pointed out by Hibernate 6 in the queries

Closes #16337
This commit is contained in:
Alexander Schwartz 2023-01-26 19:08:18 +01:00 committed by Václav Muzikář
parent 4bdf2fe21d
commit 434cc7c711
4 changed files with 15 additions and 15 deletions

View file

@ -65,7 +65,7 @@ import org.hibernate.annotations.FetchMode;
@NamedQuery(name="findResourceIdByTypeNoOwner", query="select r from ResourceEntity r left join fetch r.scopes s where r.resourceServer = :serverId and r.type = :type"),
@NamedQuery(name="findResourceIdByTypeInstance", query="select r from ResourceEntity r left join fetch r.scopes s where r.resourceServer = :serverId and r.type = :type and r.owner <> :serverId"),
@NamedQuery(name="findResourceIdByServerId", query="select r.id from ResourceEntity r where r.resourceServer = :serverId "),
@NamedQuery(name="findResourceIdByScope", query="select r from ResourceEntity r inner join r.scopes s where r.resourceServer = :serverId and (s.resourceServer = :serverId and s.id in (:scopeIds))"),
@NamedQuery(name="findResourceIdByScope", query="select r from ResourceEntity r inner join r.scopes s where r.resourceServer = :serverId and (s.resourceServer.id = :serverId and s.id in (:scopeIds))"),
@NamedQuery(name="deleteResourceByResourceServer", query="delete from ResourceEntity r where r.resourceServer = :serverId")
}
)

View file

@ -64,16 +64,16 @@ public class JPAPermissionTicketStore implements PermissionTicketStore {
@Override
public long count(ResourceServer resourceServer, Map<PermissionTicket.FilterOption, String> attributes) {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Long> querybuilder = builder.createQuery(Long.class);
CriteriaQuery<String> querybuilder = builder.createQuery(String.class);
Root<PermissionTicketEntity> root = querybuilder.from(PermissionTicketEntity.class);
querybuilder.select(root.get("id"));
List<Predicate> predicates = getPredicates(builder, root, resourceServer, attributes);
querybuilder.where(predicates.toArray(new Predicate[predicates.size()])).orderBy(builder.asc(root.get("id")));
querybuilder.where(predicates.toArray(new Predicate[0])).orderBy(builder.asc(root.get("id")));
TypedQuery query = entityManager.createQuery(querybuilder);
TypedQuery<String> query = entityManager.createQuery(querybuilder);
return closing(query.getResultStream()).count();
}

View file

@ -154,10 +154,10 @@ public class JPAResourceStore implements ResourceStore {
@Override
public List<Resource> find(RealmModel realm, ResourceServer resourceServer, Map<Resource.FilterOption, String[]> attributes, Integer firstResult, Integer maxResults) {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<ResourceEntity> querybuilder = builder.createQuery(ResourceEntity.class);
CriteriaQuery<String> querybuilder = builder.createQuery(String.class);
Root<ResourceEntity> root = querybuilder.from(ResourceEntity.class);
querybuilder.select(root.get("id"));
List<Predicate> predicates = new ArrayList();
List<Predicate> predicates = new ArrayList<>();
if (resourceServer != null) {
predicates.add(builder.equal(root.get("resourceServer"), resourceServer.getId()));
@ -196,9 +196,9 @@ public class JPAResourceStore implements ResourceStore {
}
});
querybuilder.where(predicates.toArray(new Predicate[predicates.size()])).orderBy(builder.asc(root.get("name")));
querybuilder.where(predicates.toArray(new Predicate[0])).orderBy(builder.asc(root.get("name")));
TypedQuery query = entityManager.createQuery(querybuilder);
TypedQuery<String> query = entityManager.createQuery(querybuilder);
List<String> result = paginateQuery(query, firstResult, maxResults).getResultList();
List<Resource> list = new LinkedList<>();

View file

@ -133,10 +133,10 @@ public class JPAScopeStore implements ScopeStore {
@Override
public List<Scope> findByResourceServer(ResourceServer resourceServer, Map<Scope.FilterOption, String[]> attributes, Integer firstResult, Integer maxResults) {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<ScopeEntity> querybuilder = builder.createQuery(ScopeEntity.class);
CriteriaQuery<String> querybuilder = builder.createQuery(String.class);
Root<ScopeEntity> root = querybuilder.from(ScopeEntity.class);
querybuilder.select(root.get("id"));
List<Predicate> predicates = new ArrayList();
List<Predicate> predicates = new ArrayList<>();
predicates.add(builder.equal(root.get("resourceServer").get("id"), resourceServer.getId()));
@ -153,14 +153,14 @@ public class JPAScopeStore implements ScopeStore {
}
});
querybuilder.where(predicates.toArray(new Predicate[predicates.size()])).orderBy(builder.asc(root.get("name")));
querybuilder.where(predicates.toArray(new Predicate[0])).orderBy(builder.asc(root.get("name")));
TypedQuery query = entityManager.createQuery(querybuilder);
TypedQuery<String> query = entityManager.createQuery(querybuilder);
List result = paginateQuery(query, firstResult, maxResults).getResultList();
List<String> result = paginateQuery(query, firstResult, maxResults).getResultList();
List<Scope> list = new LinkedList<>();
for (Object id : result) {
list.add(provider.getStoreFactory().getScopeStore().findById(JPAAuthorizationStoreFactory.NULL_REALM, resourceServer, (String)id));
for (String id : result) {
list.add(provider.getStoreFactory().getScopeStore().findById(JPAAuthorizationStoreFactory.NULL_REALM, resourceServer, id));
}
return list;