-->
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.  [ 4 posts ] 
Author Message
 Post subject: Types collection query error
PostPosted: Wed Apr 21, 2004 12:08 pm 
Newbie

Joined: Wed Apr 21, 2004 12:03 pm
Posts: 4
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)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 26, 2004 11:26 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
select Distinct a
from model.A a, model.B bb
where a.a1 like '%x%'
and bb.id = 2
and bb in elements (a.b)

or better (if your one to many is bidirectionnal)
select Distinct b.a
from model.B b
where b.a.a1 like '%x%'
and b.id = 2


Top
 Profile  
 
 Post subject: Still confused - many-to-many types collection
PostPosted: Tue Apr 27, 2004 9:33 am 
Newbie

Joined: Wed Apr 21, 2004 12:03 pm
Posts: 4
Thanks for your response.

I tried to implement your suggestions but was unable to make them work.

In your first suggestion:
select Distinct a
from model.A a model.B bb
where a.a1 like '%x%'
and bb.id = 2
and bb in elements (a.b)

There is no model.B so I changed that to types.B.
What is a.b? Is that a.bb?
I implemented it that way and got an error:
"WARN QueryTranslator:931 - no persistent classes found for query class"

I get the same error when I tried the second solution as well.

Thanks,

Margot


Top
 Profile  
 
 Post subject: Clarification
PostPosted: Wed Apr 28, 2004 11:15 am 
Newbie

Joined: Wed Apr 21, 2004 12:03 pm
Posts: 4
Hi again,

I realize my response was not quite clear. model.b is not a regular hibernate persistence class, it is a class that implements hibernate's PersistentEnum.

I realized I missunderstood what you meant by a.b and I did use what you suggested.

However, I still get the "no persistent classes found" error.

Thanks,

Margot


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

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.