Hello,
I'm writing a unit test to better understand how criteria queries work in combination with Map member fields. My UserGroup entity contains a domainAccessRights member, defined as Map<Domain, AccessRights>. Now I want to select all UserGroups that contain a Domain with a certain oid in their domainAccessRights. When running the text below I get this Exception: org.hibernate.QueryException: cannot dereference scalar collection element: map [select generatedAlias0 from com.fugro.gwf.domain.model.v0.security.UserGroup as generatedAlias0 inner join generatedAlias0.domainAccessRights as generatedAlias1 where generatedAlias1.map-key.oid=:param0] Does anyone know how I can fix this problem? Hibernate version is 4.2.8 ...
@Test public void jpaCriteriaQueryForMaps_TestSecondExampleFromInternet() { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<UserGroup> criteria = builder.createQuery(UserGroup.class); Root<UserGroup> root = criteria.from(UserGroup.class); MapJoin<UserGroup, Domain, AccessRights> rights = root.join(UserGroup_.domainAccessRights); criteria.where(builder.equal(rights.key().get(Domain_.oid), UserPopulationHandler.DOMAIN_FEBV_PROJECTS_OID)); List<UserGroup> resultList = entityManager.createQuery(criteria).getResultList(); Assert.assertEquals(1, resultList.size()); Assert.assertEquals(UserPopulationHandler.USERGROUP_FEBV_ADMIN_OID, resultList.get(0).getOid()); }
|