- This topic has 4 replies, 3 voices, and was last updated 19 years, 5 months ago by Scott Anderson.
-
AuthorPosts
-
arnorMemberHi to all,
I tested 4M1 with hibernate 2.1 e mysql 4.1
When I load a class with all it works nice (ex. session.load(MyTable.class, new Integer(1));)If I try this snippet:
ArrayList arrayList = null;
String SQL_STRING = “FROM my_table”;
Query query = session.createQuery(SQL_STRING);
ArrayList list = (ArrayList)query.list();
for(int i=0; i<list.size();i++){
System.out.println(list.get(i));
}my log:
2005-06-20 19:17:26,731 [main] INFO net.sf.hibernate.cfg.Environment – Hibernate 2.1.8
2005-06-20 19:17:26,734 [main] INFO net.sf.hibernate.cfg.Environment – hibernate.properties not found
2005-06-20 19:17:26,743 [main] INFO net.sf.hibernate.cfg.Environment – using CGLIB reflection optimizer
2005-06-20 19:17:26,746 [main] INFO net.sf.hibernate.cfg.Environment – using JDK 1.4 java.sql.Timestamp handling
2005-06-20 19:17:26,751 [main] INFO net.sf.hibernate.cfg.Configuration – configuring from resource: /hibernate.cfg.xml
2005-06-20 19:17:26,752 [main] INFO net.sf.hibernate.cfg.Configuration – Configuration resource: /hibernate.cfg.xml
2005-06-20 19:17:27,484 [main] INFO net.sf.hibernate.cfg.Configuration – Mapping resource: it/kemen/Registrationuser.hbm.xml
2005-06-20 19:17:27,687 [main] INFO net.sf.hibernate.cfg.Binder – Mapping class: it.kemen.Registrationuser -> registrationuser
2005-06-20 19:17:27,831 [main] INFO net.sf.hibernate.cfg.Configuration – Mapping resource: it/kemen/MyTable.hbm.xml
2005-06-20 19:17:27,875 [main] INFO net.sf.hibernate.cfg.Binder – Mapping class: it.kemen.MyTable -> my_table
2005-06-20 19:17:27,876 [main] INFO net.sf.hibernate.cfg.Configuration – Configured SessionFactory: null
2005-06-20 19:17:27,876 [main] INFO net.sf.hibernate.cfg.Configuration – processing one-to-many association mappings
2005-06-20 19:17:27,877 [main] INFO net.sf.hibernate.cfg.Configuration – processing one-to-one association property references
2005-06-20 19:17:27,877 [main] INFO net.sf.hibernate.cfg.Configuration – processing foreign key constraints
2005-06-20 19:17:27,926 [main] WARN net.sf.hibernate.cfg.SettingsFactory – No dialect set – using GenericDialect: The dialect was not set. Set the property hibernate.dialect.
2005-06-20 19:17:27,929 [main] INFO net.sf.hibernate.dialect.Dialect – Using dialect: net.sf.hibernate.dialect.GenericDialect
2005-06-20 19:17:27,942 [main] INFO net.sf.hibernate.cfg.SettingsFactory – Use outer join fetching: true
2005-06-20 19:17:27,950 [main] INFO net.sf.hibernate.connection.DriverManagerConnectionProvider – Using Hibernate built-in connection pool (not for production use!)
2005-06-20 19:17:27,951 [main] INFO net.sf.hibernate.connection.DriverManagerConnectionProvider – Hibernate connection pool size: 20
2005-06-20 19:17:27,961 [main] INFO net.sf.hibernate.connection.DriverManagerConnectionProvider – using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://127.0.0.1:3306/test
2005-06-20 19:17:27,961 [main] INFO net.sf.hibernate.connection.DriverManagerConnectionProvider – connection properties: {user=root, password=}
2005-06-20 19:17:27,988 [main] INFO net.sf.hibernate.transaction.TransactionManagerLookupFactory – No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
2005-06-20 19:17:28,431 [main] INFO net.sf.hibernate.cfg.SettingsFactory – Use scrollable result sets: true
2005-06-20 19:17:28,431 [main] INFO net.sf.hibernate.cfg.SettingsFactory – Use JDBC3 getGeneratedKeys(): true
2005-06-20 19:17:28,431 [main] INFO net.sf.hibernate.cfg.SettingsFactory – Optimize cache for minimal puts: false
2005-06-20 19:17:28,432 [main] INFO net.sf.hibernate.cfg.SettingsFactory – echoing all SQL to stdout
2005-06-20 19:17:28,432 [main] INFO net.sf.hibernate.cfg.SettingsFactory – Query language substitutions: {}
2005-06-20 19:17:28,432 [main] INFO net.sf.hibernate.cfg.SettingsFactory – cache provider: net.sf.hibernate.cache.EhCacheProvider
2005-06-20 19:17:28,444 [main] INFO net.sf.hibernate.cfg.Configuration – instantiating and configuring caches
2005-06-20 19:17:28,480 [main] WARN net.sf.ehcache.config.Configurator – No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/home/lorenzo/workspace_jsf/myfaces/WebRoot/WEB-INF/lib/ehcache-0.9.jar!/ehcache-failsafe.xml
2005-06-20 19:17:28,711 [main] INFO net.sf.hibernate.impl.SessionFactoryImpl – building session factory
2005-06-20 19:17:29,240 [main] INFO net.sf.hibernate.impl.SessionFactoryObjectFactory – Not binding factory to JNDI, no JNDI name configured
Hibernate: select from
2005-06-20 19:17:29,487 [main] WARN net.sf.hibernate.util.JDBCExceptionReporter – SQL Error: 1064, SQLState: 42000
2005-06-20 19:17:29,487 [main] 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 ‘from’ at line 1
2005-06-20 19:17:29,501 [main] WARN net.sf.hibernate.util.JDBCExceptionReporter – SQL Error: 1064, SQLState: 42000
2005-06-20 19:17:29,501 [main] 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 ‘from’ at line 1
net.sf.hibernate.exception.SQLGrammarException: Could not execute query
at net.sf.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:58)
at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at net.sf.hibernate.impl.SessionImpl.convert(SessionImpl.java:4131)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1557)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:49)
at it.kemen.jsf.TestHB.main(TestHB.java:53)
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 ‘from’ at line 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2851)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2385)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2306)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1877)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1722)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:89)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:880)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:273)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:138)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1063)
at net.sf.hibernate.loader.Loader.list(Loader.java:1054)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1554)
… 2 moreit’s very strange the sql. I get “select from” but the target table it’s missing. :/
my test hibernate.xml:
<?xml version=’1.0′ encoding=’UTF-8′?>
<!DOCTYPE hibernate-configuration PUBLIC
“-//Hibernate/Hibernate Configuration DTD 2.0//EN”
“http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd”><!– Generated by MyEclipse Hibernate Tools. –>
<hibernate-configuration><session-factory>
<!– mapping files –>
<property name=”myeclipse.connection.profile”>mysql_local</property>
<property name=”connection.url”>
jdbc:mysql://127.0.0.1:3306/test
</property>
<property name=”connection.username”>root</property>
<property name=”connection.password”></property>
<property name=”connection.driver_class”>
com.mysql.jdbc.Driver
</property>
<!– <property name=”dialect”>
net.sf.hibernate.dialect.MySQLDialect
</property>–>
<property name=”show_sql”>true</property>
<mapping resource=”it/kemen/Registrationuser.hbm.xml”></mapping><mapping resource=”it/kemen/MyTable.hbm.xml” /></session-factory>
</hibernate-configuration>
any idea?
regards lorenzo
ps. I use jdk 1.4 and mysql-connector-java-3.1.8
Riyad KallaMemberMoving to OT > Soft Dev, this is a hib question.
Arnor, what you want is .find(QUERY) not .createQuery which IIRC creates a SQL query, which is why it’s failing.
arnorMemberI can’t use find because I get this exception:
2005-06-21 09:41:40,079 [main] INFO net.sf.hibernate.impl.SessionFactoryObjectFactory – Not binding factory to JNDI, no JNDI name configured
Hibernate: select from
2005-06-21 09:41:40,337 [main] WARN net.sf.hibernate.util.JDBCExceptionReporter – SQL Error: 1064, SQLState: 42000
2005-06-21 09:41:40,337 [main] 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 ‘from’ at line 1
2005-06-21 09:41:40,344 [main] WARN net.sf.hibernate.util.JDBCExceptionReporter – SQL Error: 1064, SQLState: 42000
2005-06-21 09:41:40,345 [main] 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 ‘from’ at line 1
net.sf.hibernate.exception.SQLGrammarException: Could not execute query
at net.sf.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:58)
at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at net.sf.hibernate.impl.SessionImpl.convert(SessionImpl.java:4131)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1557)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1531)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1523)
at it.kemen.jsf.TestHB.main(TestHB.java:37)
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 ‘from’ at line 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2851)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2385)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2306)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1877)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1722)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:89)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:880)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:273)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:138)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1063)
at net.sf.hibernate.loader.Loader.list(Loader.java:1054)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1554)
… 3 moreMy snippet:
Session session = null;
try {
session = HibernateSessionFactory.currentSession();
session.find(“from registrationuser”);
} catch (HibernateException e) {
e.printStackTrace();
}
arnorMemberI solved the problem.
when I write:
session.find(“from registrationuser”);registrationuser it wasnt a class :/
anyway many thanks for the answer
regards Lorenzo
Scott AndersonParticipantLorenzo,
Thanks for following up and posting the solution so it can help others.
-
AuthorPosts