These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]

Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: JPA - Criteria query on Map field, test key member value
PostPosted: Wed Mar 12, 2014 8:03 am 

Joined: Wed Mar 12, 2014 7:51 am
Posts: 9

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 ...

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());

Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.