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
|