-->
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.  [ 5 posts ] 
Author Message
 Post subject: Quey Syntax problem, 1-*
PostPosted: Fri Nov 12, 2004 12:07 pm 
Newbie

Joined: Fri Nov 12, 2004 11:08 am
Posts: 7
Location: Amsterdam
Quite new to Hibernate, thanks in advance for your help.

Hibernate version: 2.1

Mapping documents:

Code:
<hibernate-mapping>
    <class name="com.vvdb.bus.metadata.Resource" table="RESOURCE">
        <!-- A 32 hex character is our surrogate key. It's automatically
        generated by Hibernate with the UUID pattern. -->
        <id name="uniqueId" type="string" unsaved-value="null">
            <column name="uniqueId" sql-type="char(32)" not-null="true"/>
            <generator class="uuid.hex"/>
        </id>
        <property name="dateCreated"/>
        <property name="dateModified"/>
        <property name="title"/>
        <property name="mediaType" type="com.vvdb.bus.metadata.MediaType"/>
        <!-- associations -->
        <many-to-one name="rights" column="rights_uniqueId"/>
        <many-to-one name="rightsholder" column="rightsholder_uniqueId"/>
        <!-- subclasses -->
        <joined-subclass name="com.vvdb.bus.gallery.Gallery" table="GALLERY">
            <key column="uniqueId"/>
            <property name="location" type="com.vvdb.bus.gallery.Location"/>
            <property name="activity" type="com.vvdb.bus.gallery.Activity"/>
            <property name="category" type="com.vvdb.bus.gallery.Category"/>
            <property name="thumbnailURL"/>
            <property name="galleryURL"/>
            <property name="thumbnail" type="org.springframework.orm.hibernate.support.BlobByteArrayType"/>
            <!-- associations -->
            <set name="models" table="MODEL">
                <key column="gallery_uniqueId"/>
                <one-to-many class="com.vvdb.bus.gallery.Model"/>
            </set>
        </joined-subclass>
    </class>
</hibernate-mapping>


Code:
<hibernate-mapping>
    <class name="com.vvdb.bus.metadata.Contributor" table="CONTRIBUTOR">
        <!-- A 32 hex character is our surrogate key. It's automatically
        generated by Hibernate with the UUID pattern. -->
        <id type="string" unsaved-value="null">
            <column name="uniqueId" sql-type="char(32)" not-null="true"/>
            <generator class="uuid.hex"/>
        </id>
        <property name="name"/>
        <property name="lastname"/>
        <!-- subclasses -->
        <joined-subclass name="com.vvdb.bus.gallery.Model" table="MODEL">
            <key column="uniqueId"/>
            <property name="modelOrigin" type="com.vvdb.bus.gallery.ModelOrigin"/>
    <property name="modelState" type="com.vvdb.bus.gallery.ModelState"/>
    <property name="modelType" type="com.vvdb.bus.gallery.ModelType"/>
</joined-subclass>
</class>
</hibernate-mapping>




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

I am using the Spring Hibernate Template:

Code:
public class HibernateGalleryDao extends HibernateDaoSupport implements IGalleryDao {


Code:
public List findByAttributes(Object[] values) throws DataAccessException {

        Type[] types = {Hibernate.INTEGER,
                        Hibernate.INTEGER,
                        Hibernate.INTEGER,
                        Hibernate.INTEGER,
                        Hibernate.INTEGER};

        return getHibernateTemplate().find("FROM com.vvdb.bus.gallery.Gallery AS gallery " +
                "JOIN gallery.models AS model " +
                "WHERE gallery.location = ? AND  gallery.activity = ? " +
                "AND model.modelType = ? AND model.modelState = ? AND model.modelOrigin = ?)", values, types);
    }




Full stack trace of any exception that occurs:

java.util.NoSuchElementException
at java.util.LinkedList.remove(LinkedList.java:575)
at java.util.LinkedList.removeLast(LinkedList.java:139)
at net.sf.hibernate.hql.WhereParser.closeExpression(WhereParser.java:279)
at net.sf.hibernate.hql.WhereParser.token(WhereParser.java:233)
at net.sf.hibernate.hql.WhereParser.end(WhereParser.java:275)
at net.sf.hibernate.hql.ClauseParser.endChild(ClauseParser.java:100)
at net.sf.hibernate.hql.ClauseParser.end(ClauseParser.java:108)
at net.sf.hibernate.hql.PreprocessingParser.end(PreprocessingParser.java:143)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30)
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 org.springframework.orm.hibernate.HibernateTemplate$26.doInHibernate(HibernateTemplate.java:465)
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.find(HibernateTemplate.java:459)
at com.vvdb.db.gallery.HibernateGalleryDao.findByAttributes(HibernateGalleryDao.java:59)
at com.vvdb.bus.gallery.logic.GalleryService.doSearch(GalleryService.java:42)
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 $Proxy2.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)



Name and version of the database you are using: mysql-4.0.18-win

The generated SQL (show_sql=true):

[FROM com.vvdb.bus.gallery.Gallery AS gallery JOIN gallery.models AS
model WHERE gallery.location = ? AND gallery.activity = ? AND model.modelType = ? AND model.modelState = ? AND model.modelOrigin = ?)];



Debug level Hibernate log excerpt:

16:59:14,228 DEBUG SessionFactoryObjectFactory:39 - initializing class SessionFactoryObjectFactory
16:59:14,228 DEBUG SessionFactoryObjectFactory:76 - registered: 2c9099b2002d827a01002d827d2a0000 (unnamed)
16:59:14,228 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
16:59:14,228 DEBUG SessionFactoryImpl:195 - instantiated session factory
16:59:27,028 DEBUG SessionImpl:555 - opened session
16:59:27,068 DEBUG SessionImpl:1527 - find: FROM com.vvdb.bus.gallery.Gallery AS gallery JOIN gallery.models AS model WHERE gallery.location = ? AND
gallery.activity = ? AND model.modelType = ? AND model.modelState = ? AND model.modelOrigin = ?)
16:59:27,068 DEBUG QueryParameters:109 - parameters: [0, 0, 0, 0, 0]
16:59:27,068 DEBUG QueryParameters:112 - named parameters: {}
16:59:27,098 DEBUG QueryTranslator:147 - compiling query
16:59:27,138 DEBUG QueryTranslator:165 - unexpected query compilation problem
java.util.NoSuchElementException
at java.util.LinkedList.remove(LinkedList.java:575)
at java.util.LinkedList.removeLast(LinkedList.java:139)
at net.sf.hibernate.hql.WhereParser.closeExpression(WhereParser.java:279)
at net.sf.hibernate.hql.WhereParser.token(WhereParser.java:233)
at net.sf.hibernate.hql.WhereParser.end(WhereParser.java:275)
at net.sf.hibernate.hql.ClauseParser.endChild(ClauseParser.java:100)
at net.sf.hibernate.hql.ClauseParser.end(ClauseParser.java:108)
at net.sf.hibernate.hql.PreprocessingParser.end(PreprocessingParser.java:143)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30)
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 org.springframework.orm.hibernate.HibernateTemplate$26.doInHibernate(HibernateTemplate.java:465)
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.find(HibernateTemplate.java:459)
at com.vvdb.db.gallery.HibernateGalleryDao.findByAttributes(HibernateGalleryDao.java:59)
at com.vvdb.bus.gallery.logic.GalleryService.doSearch(GalleryService.java:42)
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 $Proxy2.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)
16:59:27,148 DEBUG SessionImpl:573 - closing session
16:59:27,148 ERROR DispatcherServlet:342 - Could not complete request
org.springframework.orm.hibernate.HibernateQueryException: Incorrect query syntax [FROM com.vvdb.bus.gallery.Gallery AS gallery JOIN gallery.models AS
model WHERE gallery.location = ? AND gallery.activity = ? AND model.modelType = ? AND model.modelState = ? AND model.modelOrigin = ?)]; nested excep
tion is net.sf.hibernate.QueryException: Incorrect query syntax [FROM com.vvdb.bus.gallery.Gallery AS gallery JOIN gallery.models AS model WHERE galle
ry.location = ? AND gallery.activity = ? AND model.modelType = ? AND model.modelState = ? AND model.modelOrigin = ?)]
net.sf.hibernate.QueryException: Incorrect query syntax [FROM com.vvdb.bus.gallery.Gallery AS gallery JOIN gallery.models AS model WHERE gallery.locat
ion = ? AND gallery.activity = ? AND model.modelType = ? AND model.modelState = ? AND model.modelOrigin = ?)]
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:166)
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 org.springframework.orm.hibernate.HibernateTemplate$26.doInHibernate(HibernateTemplate.java:465)
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.find(HibernateTemplate.java:459)
at com.vvdb.db.gallery.HibernateGalleryDao.findByAttributes(HibernateGalleryDao.java:59)
at com.vvdb.bus.gallery.logic.GalleryService.doSearch(GalleryService.java:42)
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 $Proxy2.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)
Caused by: java.util.NoSuchElementException
at java.util.LinkedList.remove(LinkedList.java:575)
at java.util.LinkedList.removeLast(LinkedList.java:139)
at net.sf.hibernate.hql.WhereParser.closeExpression(WhereParser.java:279)
at net.sf.hibernate.hql.WhereParser.token(WhereParser.java:233)
at net.sf.hibernate.hql.WhereParser.end(WhereParser.java:275)
at net.sf.hibernate.hql.ClauseParser.endChild(ClauseParser.java:100)
at net.sf.hibernate.hql.ClauseParser.end(ClauseParser.java:108)
at net.sf.hibernate.hql.PreprocessingParser.end(PreprocessingParser.java:143)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)
... 50 more
16:59:27,158 DEBUG SessionImpl:3388 - running Session.finalize()


[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 12, 2004 1:20 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
FROM com.vvdb.bus.gallery.Gallery AS gallery
JOIN gallery.models AS model
WHERE gallery.location = ?
AND gallery.activity = ?
AND model.modelType = ?
AND model.modelState = ?
AND model.modelOrigin = ?

FROM com.vvdb.bus.gallery.Gallery AS gallery
JOIN gallery.models AS models,
com.vvdb.bus.gallery.Model AS model
WHERE gallery.location = ?
AND gallery.activity = ?
AND model.modelType = ?
AND model.modelState = ?
AND model.modelOrigin = ?
and model in elements(models)
// or and model in elements(gallery.models)

also think about using named parameter and string buffer

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 15, 2004 5:58 am 
Newbie

Joined: Fri Nov 12, 2004 11:08 am
Posts: 7
Location: Amsterdam
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))


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 15, 2004 11:29 am 
Newbie

Joined: Fri Nov 12, 2004 11:08 am
Posts: 7
Location: Amsterdam
Could the problem be caused by current limitations of Hibernate on MySQL that no subselects are supported? See: http://www.hibernate.org/80.html


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 15, 2004 12:25 pm 
Newbie

Joined: Fri Nov 12, 2004 11:08 am
Posts: 7
Location: Amsterdam
I changed the Query to
Code:
... AND model IN elements(models)
. This leads to generated sql without a subselect and thus a working application.

Solving this problem was quite an enlightening experience .... Thanks Anthony.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.