-->
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: How to write HQL with a where clause on a Set of UserType
PostPosted: Fri Dec 03, 2004 6:14 pm 
Newbie

Joined: Fri Aug 20, 2004 10:56 am
Posts: 2
Hibernate version:
2.1.6

Mapping documents:

Summarised as:
<class name="User" table="users">
<id name="userId" type="UserId" unsaved-value="null">
<generator class="assigned"/>
</id>
<property name="enabled" type="boolean" not-null="true"/>
<set name="roles" table="user_roles">
<key column="user_id"/>
<element column="role" not-null="true" type="UserRole"/>
</set>
</class>

Code between sessionFactory.openSession() and session.close():

This is my problem query

Integer users = (Integer) session.createQuery(
"SELECT COUNT(*) FROM User u" +
" WHERE u.enabled = :enabled AND u.roles = :role")
.setBoolean("enabled", true)
.setEntity("role", role)
.uniqueResult();


Full stack trace of any exception that occurs:

net.sf.hibernate.QueryException: unindexed collection before []: user0_.roles [SELECT COUNT(*) FROM com.openeln.patentsafe.server.users.User u WHERE u.enabled = :enabled AND u.roles = :role]
at net.sf.hibernate.hql.PathExpressionParser.prepareForIndex(PathExpressionParser.java:308)
at net.sf.hibernate.hql.PathExpressionParser.end(PathExpressionParser.java:292)
at net.sf.hibernate.hql.WhereParser.doPathExpression(WhereParser.java:336)
at net.sf.hibernate.hql.WhereParser.doToken(WhereParser.java:366)
at net.sf.hibernate.hql.WhereParser.token(WhereParser.java:251)
at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
at net.sf.hibernate.hql.PreprocessingParser.token(PreprocessingParser.java:123)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:294)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1562)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1533)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at net.sf.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:550)

Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:


The problem I am having is that the role Set is just a collecion of unique values, rather than mapping to another Class. I can't determine what join options will work to get at the members of this table.

Any ideas?

Cheers
Kevin


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