-->
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.  [ 8 posts ] 
Author Message
 Post subject: Unable to perform find
PostPosted: Tue Mar 07, 2006 6:28 pm 
Beginner
Beginner

Joined: Tue Feb 08, 2005 1:29 pm
Posts: 20
Hibernate version: 2.1

Mapping documents:
<hibernate-mapping package="com.etil.sudetp.business.manager.user.impl" >
<class name="Feedback" table="feedback" >
<composite-id>
<key-property name="userId"/>
<key-property name="tradeNo"/>
<key-property name="side"/>
</composite-id>
<property name="positive" type="int" column="S" />
<property name="neutral" type="int" column="N" />
<property name="negative" type="int" column="D" />
<property name="cptyUserId" type="string" column="CPTYUSERID" />
<property name="date" type="java.util.Date" column="DATE" />
<property name="comment" type="string" column="COMMENT" />
<property name="trade" type="string" column="TRADE" />
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Criteria criteria = session.createCriteria(Feedback.class);
criteria.setMaxResults(100);
Feedback.KEYRECORD);
List feedbacks = criteria.list();

Name and version of the database you are using:
MySQL

And the error is "Unable to perform find". I have found in the forum something related, but no proper responses were given. Any one can help me there?

Cheers.
ingenu


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 07, 2006 9:45 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Can you post the full exception trace? Preferably in code tags. Also, can you post the problem code again, the code you posted above seems to be missing a chunk.


Top
 Profile  
 
 Post subject: The trace
PostPosted: Wed Mar 08, 2006 3:39 am 
Beginner
Beginner

Joined: Tue Feb 08, 2005 1:29 pm
Posts: 20
com.etil.base.error.ErrorManager 2006-03-07 20:57:48,830 ERROR [http-0.0.0.0-8080-Processor25] - net.sf.hibernate.exception.SQLGrammarException: Could not execute query
at net.sf.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:69)
at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:30)
at net.sf.hibernate.impl.SessionImpl.convert(SessionImpl.java:4110)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1556)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at com.etil.sudetp.business.manager.user.UserManager.inquireProfileCommunity(UserManager.java:371)
at com.etil.sudetp.business.manager.user.UserManager.processRequest(UserManager.java:192)
at com.etil.sudetp.business.manager.BaseManager.processRequest(BaseManager.java:132)
at com.etil.sudetp.presentation.SyncRouter.process(SyncRouter.java:39)
at com.etil.sudetp.presentation.http.page.ViewProfileCommunity.loadPage(ViewProfileCommunity.java:88)
at com.etil.sudetp.presentation.http.page.ViewProfileCommunity.activateExternalPageImpl(ViewProfileCommunity.java:81)
at com.etil.sudetp.presentation.http.page.BidNPlayPage.activateExternalPage(BidNPlayPage.java:41)
at org.apache.tapestry.engine.ExternalService.service(ExternalService.java:161)
at org.apache.tapestry.engine.AbstractEngine.service(AbstractEngine.java:872)
at org.apache.tapestry.ApplicationServlet.doService(ApplicationServlet.java:197)
at org.apache.tapestry.ApplicationServlet.doGet(ApplicationServlet.java:158)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
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.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:66)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:158)
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.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
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:534)
Caused by: java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2851)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1534)
at com.mysql.jdbc.ServerPreparedStatement.serverPrepare(ServerPreparedStatement.java:1485)
at com.mysql.jdbc.ServerPreparedStatement.<init>(ServerPreparedStatement.java:151)
at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1309)
at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1281)
at net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:260)
at net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:235)
at net.sf.hibernate.impl.BatcherImpl.prepareQueryStatement(BatcherImpl.java:66)
at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:779)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:265)
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:1553)
... 45 more

Which other code could be missing, apart from the initialisation of the session?


Top
 Profile  
 
 Post subject: Configuration Files
PostPosted: Wed Mar 08, 2006 3:39 am 
Beginner
Beginner

Joined: Tue Feb 08, 2005 1:29 pm
Posts: 20
######################
### Query Language ###
######################

## define query language constants / function names

hibernate.query.substitutions true 1, false 0, yes 'Y', no 'N'



#################
### Platforms ###
#################

## JNDI Datasource

#hibernate.connection.datasource jdbc/test
#hibernate.connection.username db2
#hibernate.connection.password db2


## MySQL

hibernate.dialect net.sf.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class org.gjt.mm.mysql.Driver
hibernate.connection.driver_class com.mysql.jdbc.Driver
hibernate.connection.url jdbc:mysql:///test
hibernate.connection.username root
hibernate.connection.password puifefof

#################################
### Hibernate Connection Pool ###
#################################

hibernate.connection.pool_size 1



###########################
### C3P0 Connection Pool###
###########################

#hibernate.c3p0.max_size 2
#hibernate.c3p0.min_size 2
#hibernate.c3p0.timeout 5000
#hibernate.c3p0.max_statements 100
#hibernate.c3p0.idle_test_period 3000
#hibernate.c3p0.acquire_increment 2
##hibernate.c3p0.validate false



###################################
### Apache DBCP Connection Pool ###
###################################

## connection pool

#hibernate.dbcp.maxActive 100
#hibernate.dbcp.whenExhaustedAction 1
#hibernate.dbcp.maxWait 120000
#hibernate.dbcp.maxIdle 10

## prepared statement cache

#hibernate.dbcp.ps.maxActive 100
#hibernate.dbcp.ps.whenExhaustedAction 1
#hibernate.dbcp.ps.maxWait 120000
#hibernate.dbcp.ps.maxIdle 10

## optional query to validate pooled connections:

#hibernate.dbcp.validationQuery select 1 from dual
#hibernate.dbcp.testOnBorrow true
#hibernate.dbcp.testOnReturn false



##############################
### Proxool Connection Pool###
##############################

## Properties for external configuration of Proxool

hibernate.proxool.pool_alias pool1

## Only need one of the following

#hibernate.proxool.existing_pool true
#hibernate.proxool.xml proxool.xml
#hibernate.proxool.properties proxool.properties



#################################
### Plugin ConnectionProvider ###
#################################

## use a custom ConnectionProvider (if not set, Hibernate will choose a built-in ConnectionProvider using hueristics)

#hibernate.connection.provider_class net.sf.hibernate.connection.DriverManagerConnectionProvider
#hibernate.connection.provider_class net.sf.hibernate.connection.DatasourceConnectionProvider
#hibernate.connection.provider_class net.sf.hibernate.connection.C3P0ConnectionProvider
#hibernate.connection.provider_class net.sf.hibernate.connection.DBCPConnectionProvider
#hibernate.connection.provider_class net.sf.hibernate.connection.ProxoolConnectionProvider



#######################
### Transaction API ###
#######################

## the Transaction API abstracts application code from the underlying JTA or JDBC transactions

#hibernate.transaction.factory_class net.sf.hibernate.transaction.JTATransactionFactory
hibernate.transaction.factory_class net.sf.hibernate.transaction.JDBCTransactionFactory


## to use JTATransactionFactory, Hibernate must be able to locate the UserTransaction in JNDI
## default is java:comp/UserTransaction
## you do NOT need this setting if you specify hibernate.transaction.manager_lookup_class

#jta.UserTransaction jta/usertransaction
#jta.UserTransaction javax.transaction.UserTransaction
#jta.UserTransaction UserTransaction


## to use JCS caching with JTA, Hibernate must be able to obtain the JTA TransactionManager

#hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.JBossTransactionManagerLookup
#hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.WeblogicTransactionManagerLookup
#hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.WebSphereTransactionManagerLookup
#hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.OrionTransactionManagerLookup
#hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.ResinTransactionManagerLookup



##############################
### Miscellaneous Settings ###
##############################

## print all generated SQL to the console

hibernate.show_sql true


## auto schema export

#hibernate.hbm2ddl.auto create-drop
#hibernate.hbm2ddl.auto create
#hibernate.hbm2ddl.auto update


## specify a JDBC isolation level

#hibernate.connection.isolation 4


## set the JDBC fetch size

#hibernate.jdbc.fetch_size 25


## set the maximum JDBC 2 batch size (a nonzero value enables batching)

hibernate.jdbc.batch_size 0

## use JDBC batching for versioned data

hibernate.jdbc.batch_versioned_data true

## enable use of JDBC 2 scrollable ResultSets (specifying a Dialect will cause Hibernate to use a sensible default)

#hibernate.jdbc.use_scrollable_resultset true


## use streams when writing binary types to / from JDBC

hibernate.jdbc.use_streams_for_binary true


## use JDBC 3 PreparedStatement.getGeneratedKeys to get the identifier of an inserted row

#hibernate.jdbc.use_get_generated_keys true


## specify a default schema for unqualified tablenames

#hibernate.default_schema test


## use a custom stylesheet for XML generation (if not specified, hibernate-default.xslt will be used)

#hibernate.xml.output_stylesheet C:/Hibernate/net/sf/hibernate/hibernate-default.xslt


## enable outerjoin fetching (specifying a Dialect will cause Hibernate to use sensible default)

#hibernate.use_outer_join false


## set the maximum depth of the outer join fetch tree

hibernate.max_fetch_depth 1


## enable CGLIB reflection optimizer (enabled by default)

#hibernate.cglib.use_reflection_optimizer false



##########################
### Second-level Cache ###
##########################

## optimize chache for minimal "puts" instead of minimal "gets" (good for clustered cache)

#hibernate.cache.use_minimal_puts true


## set a prefix for cache region names

hibernate.cache.region_prefix hibernate.test


## enable the query cache

hibernate.cache.use_query_cache false


## choose a cache implementation

hibernate.cache.provider_class net.sf.hibernate.cache.EhCacheProvider
#hibernate.cache.provider_class net.sf.hibernate.cache.EmptyCacheProvider
#hibernate.cache.provider_class net.sf.hibernate.cache.HashtableCacheProvider
#hibernate.cache.provider_class net.sf.hibernate.cache.TreeCacheProvider
#hibernate.cache.provider_class net.sf.hibernate.cache.OSCacheProvider
#hibernate.cache.provider_class net.sf.hibernate.cache.JCSCacheProvider
#hibernate.cache.provider_class net.sf.hibernate.cache.SwarmCacheProvider



############
### JNDI ###
############

## specify a JNDI name for the SessionFactory

#hibernate.session_factory_name hibernate/session_factory


## Hibernate uses JNDI to bind a name to a SessionFactory and to look up the JTA UserTransaction;
## if hibernate.jndi.* are not specified, Hibernate will use the default InitialContext() which
## is the best approach in an application server

#file system
#hibernate.jndi.class com.sun.jndi.fscontext.RefFSContextFactory
#hibernate.jndi.url file:/

#WebSphere
#hibernate.jndi.class com.ibm.websphere.naming.WsnInitialContextFactory
#hibernate.jndi.url iiop://localhost:900/


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 5:00 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
The missing code that I was referring to is in this chunk, from your original post:
Code:
Criteria criteria = session.createCriteria(Feedback.class);
criteria.setMaxResults(100);
Feedback.KEYRECORD);
List feedbacks = criteria.list();
There's something missing there, what is it?

Your improved exception report has this informative bit:
Code:
Caused by: java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1
That's slightly odd, seeing as your query seems to be just "find all Feedbacks", so there shouldn't be any parameters. Of course, the missing chunk ending in "Feedback.KEYRECORD);" (above) may explain all of this.

When you're posting the missing code, can you also post the SQL output? Set show_sql to true, rerun the code, and look for the select select statements in your debug output. Thanks.


Top
 Profile  
 
 Post subject: My SQL Trace
PostPosted: Wed Mar 08, 2006 5:51 pm 
Beginner
Beginner

Joined: Tue Feb 08, 2005 1:29 pm
Posts: 20
I think this is the trace related to my problem:

2006-03-08 21:46:08,399 70892 INFO [STDOUT] Hibernate: select this.userId as userId0_, this.tradeNo as tradeNo0_, this.side as side0_, this.S as S0_, this.N as N0_, this.D as D0_, this.CPTYUSERID as CPTYUSERID0_, this.DATE as DATE0_, this.COMMENT as COMMENT0_, this.TRADE as TRADE0_ from feedback this where 1=1 limit ?
2006-03-08 21:46:08,459 70952 ERROR [net.sf.hibernate.util.JDBCExceptionReporter] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1
2006-03-08 21:46:08,459 70952 ERROR [net.sf.hibernate.util.JDBCExceptionReporter] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1

Just ignore the "Feedback.KEYRECORD); ". I reduced my code to the minimum in order to try to identify the problem... This code is not executed.

Cheers.
DvJ


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 6:25 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
The "limit ?" is what's in the 2.1 hibernate code, and in 3.1.1, so it's been working for quite some time. I have confidence that the SQL syntax isn't wrong, at least for most MySQL users. Is it possible that you have a really, really old MySQL DB, that doesn't supprt the limit syntax? What happens when you run that SQL on your DB server, replacing the ? with 100?

There's no logging code in the relevant method, but if you've got a useful debugger and the source code for hibernate, you could put a breakpoint in net.sf.hibernate.loader.Loader.bindLiimitParameters and ensure that the st.setInt() line is being executed.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 6:44 pm 
Beginner
Beginner

Joined: Tue Feb 08, 2005 1:29 pm
Posts: 20
Query execute just great! I guess I will try to compile hibernate 2.1 and see what is going on from it.... Not my favorite idea, but maybe my only solution apart from upgrading to 3


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