Anthony,
thanks for the help.
I changed the calling code to:
Code:
public List findByAttributes(Object[] values) throws DataAccessException {
Type[] types = {Hibernate.INTEGER,
Hibernate.INTEGER,
Hibernate.INTEGER,
Hibernate.INTEGER,
Hibernate.INTEGER};
String[] paramNames = {"location", "activity", "modelType", "modelState", "modelOrigin"};
StringBuffer query = new StringBuffer();
query.append("FROM com.vvdb.bus.gallery.Gallery AS gallery ");
query.append("JOIN gallery.models AS models, ");
query.append("com.vvdb.bus.gallery.Model AS model ");
query.append("WHERE gallery.location = :location AND gallery.activity = :activity ");
query.append("AND model.modelType = :modelType AND model.modelState = :modelState ");
query.append("AND model.modelOrigin = :modelOrigin ");
query.append("AND model IN elements(gallery.models)");
return getHibernateTemplate().findByNamedParam(query.toString(), paramNames, values, types);
}
Before, the models attribute in the Gallery object was defined as a Collection, I changed that as well to a Set, because I think it was incorrect:
Code:
public class Gallery extends Resource implements Serializable{
private Set models;
public Set getModels() {
return models;
}
public void setModels(Set models) {
this.models = models;
}
...}
I am getting another exception now:
java.sql.SQLException: Syntax error or access violation, message from server: "You have an error in your SQL syntax. Check the manual that correspon
ds to your MySQL server version for the right syntax to use near 'select models3_.uniqueId from MODEL models3_ where gallery0_.un"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1977)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1163)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1272)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2236)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1555)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:875)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:269)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at org.springframework.orm.hibernate.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:524)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:176)
at org.springframework.orm.hibernate.HibernateTemplate.executeFind(HibernateTemplate.java:196)
at org.springframework.orm.hibernate.HibernateTemplate.findByNamedParam(HibernateTemplate.java:518)
at com.vvdb.db.gallery.HibernateGalleryDao.findByAttributes(HibernateGalleryDao.java:70)
at com.vvdb.bus.gallery.logic.GalleryService.doSearch(GalleryService.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.springframework.aop.framework.AopProxyUtils.invokeJoinpointUsingReflection(AopProxyUtils.java:61)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:142)
at $Proxy0.doSearch(Unknown Source)
at com.vvdb.web.gallery.SearchController.onSubmit(SearchController.java:55)
at org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:223)
at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:237)
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:121)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:495)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:321)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:536)
10:39:55,086 WARN JDBCExceptionReporter:38 - SQL Error: 1064, SQLState: 42000
The generated SQL looks as follows:
QueryTranslator:208 - SQL: select gallery0_.uniqueId as uniqueId0_, models1_.uniqueId as uniqueId1_, model2_.uniqueId as uniqueId2_
, gallery0_.location as location5_0_, gallery0_.activity as activity5_0_, gallery0_.category as category5_0_, gallery0_.thumbnailURL as thumbnai5_5_0_
, gallery0_.galleryURL as galleryURL5_0_, gallery0_.thumbnail as thumbnail5_0_, gallery0__1_.dateCreated as dateCrea2_4_0_, gallery0__1_.dateModified
as dateModi3_4_0_, gallery0__1_.title as title4_0_, gallery0__1_.mediaType as mediaType4_0_, gallery0__1_.rights_uniqueId as rights_u6_4_0_, gallery0_
_1_.rightsholder_uniqueId as rightsho7_4_0_, models1_.modelOrigin as modelOri2_1_1_, models1_.modelState as modelState1_1_, models1_.modelType as mode
lType1_1_, models1__1_.name as name0_1_, models1__1_.lastname as lastname0_1_, model2_.modelOrigin as modelOri2_1_2_, model2_.modelState as modelState
1_2_, model2_.modelType as modelType1_2_, model2__1_.name as name0_2_, model2__1_.lastname as lastname0_2_ from GALLERY gallery0_ inner join RESOURCE
gallery0__1_ on gallery0_.uniqueId=gallery0__1_.uniqueId inner join MODEL models1_ on gallery0_.uniqueId=models1_.gallery_uniqueId left outer join CON
TRIBUTOR models1__1_ on models1_.uniqueId=models1__1_.uniqueId, MODEL model2_ inner join CONTRIBUTOR model2__1_ on model2_.uniqueId=model2__1_.uniqueI
d where (gallery0_.location=? )AND(gallery0_.activity=? )AND(model2_.modelType=? )AND(model2_.modelState=? )AND(model2_.modelOrigin=? )AND(model2_.uni
queId IN(select models3_.uniqueId from MODEL models3_ where gallery0_.uniqueId=models3_.gallery_uniqueId))