Folks,
We are getting an error when we query using hibernate in a particular situation. We have a many-to-many relationship between a persistent class and a hibernate persistent enum. The queries work fine if the constraints are just based on values from the persistent class. The returned objects correctly return the associated persistent enum values. However, if we want to make a query based on the value of one of the persistent values, we get error: net.sf.hibernate.QueryException: unindexed collection before []. Is there an error in our mapping or in our query?
Table a has the following values in its model class (The setter methods were removed to make the note more concise) :
private Long id;
private String a1;
private Set b;
/**
* @hibernate.id generator-class="uuid.hex"
*/
public Long getId() {
return this.id;
}
/**
* @hibernate.property length="60" not-null="true"
*/
public String getA1() {
return this.a1;
}
/**
* @hibernate.set table="aTob" lazy="false" cascade="none" readonly="true"
* @hibernate.collection-key column="aid"
* @hibernate.collection-element column="bid" type="types.bType" not-null="true"
* @return Set of b objects
* The class types.bType implements the hibernate PersistentEnum interface
*/
public Set getB()
{
return this.b;
}
Hibernate generates the following sql from this information:
create table a (
id BIGINT not null,
a1 VARCHAR(60) not null,
primary key (id)
);
create table aTob (
aid BIGINT not null,
bid SMALLINT not null,
primary key (aid, bid)
);
I have tried many variations but I can't seem to write sql where I select all a
where bid equals a value. For example, some of the variations are:
select Distinct a from model.A a where a.a1 like '%x%' and a.b = 2
select a from model.A a where a.a1 like '%x%' and a.b = 2
select a from model.A a, aTob map where a.a1 like '%x%' and a.b = 2 and a.id = map.aid
In the simplest query I get the following error (see below). Any suggestions?
Problem with hibernatenet.sf.hibernate.QueryException: unindexed collection before []: a0_.b [ select Distinct a from model.A a where a.a1 like '%xxx%' and a.b = 2]
:unindexed collection before []: a0_.b [ select Distinct a from model.A a where a.a1 like '%x%' and a.b = 2]
net.sf.hibernate.QueryException: unindexed collection before []: a0_.b [ select Distinct a from model.A a where a.a1 like '%x%' and a.b = 2]
at net.sf.hibernate.hql.PathExpressionParser.prepareForIndex(PathExpressionParser.java:303)
at net.sf.hibernate.hql.PathExpressionParser.end(PathExpressionParser.java:287)
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:293)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1530)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1501)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at gov.nih.nci.lmp.abminer.AntibodyQueryBean.getAntibodies(AntibodyQueryBean.java:121)
at org.apache.jsp.browseAntibody_jsp._jspService(browseAntibody_jsp.java:87)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) \
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2416)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:601)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
at java.lang.Thread.run(Thread.java:536)
|