Hibernate version: 2.1.4
Mapping documents
<hibernate-mapping>
<class name="org.rmap.model.Control" table="controls">
<id name="id" column="cod_id_control" type="long" unsaved-value="0">
<generator class="native"/>
</id>
<property name="name" column="txt_name_control" type="string"/>
<property name="description" column="txt_desc_control" type="text"/>
<property name="author" column="txt_author_control" type="string"/>
<property name="copyright" column="txt_copyr_control" type="string"/>
<property name="date" column="txt_date_control" type="string"/>
<property name="version" column="txt_version_control" type="string"/>
<property name="platform" column="cod_platform_control" type="int"/>
<property name="web" column="txt_web_control" type="string"/>
<property name="type" column="cod_type_control" type="int"/>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="org.rmap.model.Sensor" table="sensors">
<id name="id" column="cod_id_sensor" type="long" unsaved-value="0">
<generator class="native"/>
</id>
<property name="name" column="txt_name_sensor" type="string"/>
<property name="description" column="txt_desc_sensor" type="text"/>
<property name="author" column="txt_author_sensor" type="string"/>
<property name="copyright" column="txt_copyr_sensor" type="string"/>
<property name="date" column="txt_date_sensor" type="string"/>
<property name="version" column="txt_version_sensor" type="string"/>
<property name="platform" column="cod_platform_sensor" type="int"/>
<property name="web" column="txt_web_sensor" type="string"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
//org.rmap.model.Plugin admin = new org.rmap.model.Sensor("pe","gpl","10-04-2005","jarls, peperl, nu pedor","superPepe","1.0",1,"pepe.net");
//admin.setType(2);
//session.save(admin);
List admins = session.find("from Plugin");
java.util.Iterator iterator = admins.iterator();
while (iterator.hasNext()) {
org.rmap.model.Plugin pepe = (org.rmap.model.Plugin) iterator.next();
System.out.println(pepe.getName());
//session.delete(pepe);
}
tx.commit();
session.close();
Full stack trace of any exception that occurs:
17:31:21,095 INFO Environment:462 - Hibernate 2.1.4
17:31:21,150 INFO Environment:496 - loaded properties from resource hibernate.properties: {hibernate.c3p0.timeout=1800, hibernate.connection.driver_class=org.gjt.mm.mysql.Driver, hibernate.cglib.use_reflection_optimizer=true, hibernate.c3p0.max_statements=50, hibernate.c3p0.max_size=15, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.c3p0.min_size=5, hibernate.connection.username=rmap, hibernate.connection.url=jdbc:mysql://localhost/rmap_server, hibernate.connection.password=pepeluis}
17:31:21,164 INFO Environment:522 - using CGLIB reflection optimizer
17:31:21,205 INFO Configuration:347 - Mapping resource: org/rmap/model/Control.hbm.xml
17:31:23,232 DEBUG DTDEntityResolver:20 - trying to locate
http://hibernate.sourceforge.net/hibernate-mapping.dtd in classpath under net/sf/hibernate/
17:31:23,235 DEBUG DTDEntityResolver:25 -
http://hibernate.sourceforge.net/hibern ... ing.dtdnot found in classpath
17:31:25,398 INFO Binder:229 - Mapping class: org.rmap.model.Control -> controls
17:31:25,692 DEBUG Binder:475 - Mapped property: id -> cod_id_control, type: long
17:31:25,736 DEBUG Binder:475 - Mapped property: name -> txt_name_control, type: string
17:31:25,738 DEBUG Binder:475 - Mapped property: description -> txt_desc_control, type: text
17:31:25,739 DEBUG Binder:475 - Mapped property: author -> txt_author_control, type: string
17:31:25,741 DEBUG Binder:475 - Mapped property: copyright -> txt_copyr_control, type: string
17:31:25,742 DEBUG Binder:475 - Mapped property: date -> txt_date_control, type: string
17:31:25,752 DEBUG Binder:475 - Mapped property: version -> txt_version_control, type: string
17:31:25,754 DEBUG Binder:475 - Mapped property: platform -> cod_platform_control, type: integer
17:31:25,755 DEBUG Binder:475 - Mapped property: web -> txt_web_control, type: string
17:31:25,756 DEBUG Binder:475 - Mapped property: type -> cod_type_control, type: integer
17:31:25,759 INFO Configuration:347 - Mapping resource: org/rmap/model/Sensor.hbm.xml
17:31:25,773 DEBUG DTDEntityResolver:20 - trying to locate
http://hibernate.sourceforge.net/hibernate-mapping.dtd in classpath under net/sf/hibernate/
17:31:25,776 DEBUG DTDEntityResolver:25 -
http://hibernate.sourceforge.net/hibern ... ing.dtdnot found in classpath
17:31:27,306 INFO Binder:229 - Mapping class: org.rmap.model.Sensor -> sensors
17:31:27,313 DEBUG Binder:475 - Mapped property: id -> cod_id_sensor, type: long
17:31:27,314 DEBUG Binder:475 - Mapped property: name -> txt_name_sensor, type: string
17:31:27,315 DEBUG Binder:475 - Mapped property: description -> txt_desc_sensor, type: text
17:31:27,316 DEBUG Binder:475 - Mapped property: author -> txt_author_sensor, type: string
17:31:27,317 DEBUG Binder:475 - Mapped property: copyright -> txt_copyr_sensor, type: string
17:31:27,323 DEBUG Binder:475 - Mapped property: date -> txt_date_sensor, type: string
17:31:27,324 DEBUG Binder:475 - Mapped property: version -> txt_version_sensor, type: string
17:31:27,325 DEBUG Binder:475 - Mapped property: platform -> cod_platform_sensor, type: integer
17:31:27,326 DEBUG Binder:475 - Mapped property: web -> txt_web_sensor, type: string
17:31:27,327 INFO Configuration:613 - processing one-to-many association mappings
17:31:27,328 INFO Configuration:622 - processing one-to-one association property references
17:31:27,328 INFO Configuration:647 - processing foreign key constraints
17:31:27,399 INFO Dialect:82 - Using dialect: net.sf.hibernate.dialect.MySQLDialect
17:31:27,408 INFO SettingsFactory:62 - Use outer join fetching: false
17:31:27,423 INFO C3P0ConnectionProvider:48 - C3P0 using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://localhost/rmap_server
17:31:27,424 INFO C3P0ConnectionProvider:49 - Connection properties: {user=rmap, password=pepeluis}
17:31:27,583 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@1315d34 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@e32802 [ acquireIncrement -> 1, autoCommitOnClose -> false, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, idleConnectionTestPeriod -> 0, initialPoolSize -> 5, maxIdleTime -> 1800, maxPoolSize -> 15, maxStatements -> 50, minPoolSize -> 5, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@1de256f [ description -> null, driverClass -> null, factoryClassLocation -> null, jdbcUrl -> jdbc:mysql://localhost/rmap_server, properties -> {user=rmap, password=pepeluis} ] , propertyCycle -> 300, testConnectionOnCheckout -> false ] , factoryClassLocation -> null, numHelperThreads -> 3 ]
17:31:28,562 INFO SettingsFactory:102 - Use scrollable result sets: true
17:31:28,563 INFO SettingsFactory:105 - Use JDBC3 getGeneratedKeys(): true
17:31:28,564 INFO SettingsFactory:108 - Optimize cache for minimal puts: false
17:31:28,565 INFO SettingsFactory:117 - Query language substitutions: {}
17:31:28,565 INFO SettingsFactory:128 - cache provider: net.sf.ehcache.hibernate.Provider
17:31:28,574 INFO Configuration:1093 - instantiating and configuring caches
17:31:29,139 INFO SessionFactoryImpl:119 - building session factory
17:31:29,146 DEBUG SessionFactoryImpl:125 - instantiating session factory with properties: {java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, hibernate.connection.password=pepeluis, sun.boot.library.path=/usr/share/j2sdk1.4.2/jre/lib/i386, java.vm.version=1.4.2-b28, hibernate.connection.username=rmap, java.vm.vendor=Sun Microsystems Inc., java.vendor.url=http://java.sun.com/, path.separator=:, java.vm.name=Java HotSpot(TM) Client VM, file.encoding.pkg=sun.io, user.country=ES, sun.os.patch.level=unknown, java.vm.specification.name=Java Virtual Machine Specification, user.dir=/data/Practicas/pfc/build/client, java.runtime.version=1.4.2-b28, java.awt.graphicsenv=sun.awt.X11GraphicsEnvironment, java.endorsed.dirs=/usr/share/j2sdk1.4.2/jre/lib/endorsed, os.arch=i386, hibernate.c3p0.max_statements=50, java.io.tmpdir=/tmp, line.separator=
, java.vm.specification.vendor=Sun Microsystems Inc., os.name=Linux, sun.java2d.fontpath=, hibernate.c3p0.timeout=1800, java.library.path=/usr/share/j2sdk1.4.2/jre/lib/i386/client:/usr/share/j2sdk1.4.2/jre/lib/i386:/usr/share/j2sdk1.4.2/jre/../lib/i386, java.specification.name=Java Platform API Specification, java.class.version=48.0, java.util.prefs.PreferencesFactory=java.util.prefs.FileSystemPreferencesFactory, os.version=2.4.26, user.home=/home/inggvf01, user.timezone=America/New_York, java.awt.printerjob=sun.print.PSPrinterJob, file.encoding=UTF-8, java.specification.version=1.4, hibernate.c3p0.min_size=5, hibernate.connection.driver_class=org.gjt.mm.mysql.Driver, java.class.path=/home/inggvf01/.netbeans/3.5/system:/home/inggvf01/.netbeans/3.5/system:/usr/local/NetBeans_3.5.1/system:/usr/local/NetBeans_3.5.1/modules/ext/AbsoluteLayout.jar:/usr/local/NetBeans_3.5.1/modules/autoload/ext/servlet-2.3.jar:/usr/local/NetBeans_3.5.1/lib/ext/xml-apis-1.0b2.jar:/usr/local/NetBeans_3.5.1/beans/TimerBean.jar:/data/Practicas/pfc/src:/data/Practicas/pfc/pruebas:/data/Practicas/pfc/build/server/conf:/data/Practicas/pfc/build/server:/data/Practicas/pfc/build/server/lib/ant.jar:/data/Practicas/pfc/build/server/lib/cglib-full-2.0.1.jar:/data/Practicas/pfc/build/server/lib/commons-collections-2.1.jar:/data/Practicas/pfc/build/server/lib/commons-logging-1.0.3.jar:/data/Practicas/pfc/build/server/lib/dom4j-1.4.jar:/data/Practicas/pfc/build/server/lib/ehcache-0.9.jar:/data/Practicas/pfc/build/server/lib/exolabcore-0.3.7.jar:/data/Practicas/pfc/build/server/lib/hibernate2.jar:/data/Practicas/pfc/build/server/lib/jasper-compiler.jar:/data/Practicas/pfc/build/server/lib/jasper-runtime.jar:/data/Practicas/pfc/build/server/lib/jdom.jar:/data/Practicas/pfc/build/server/lib/jms-1.0.2a.jar:/data/Practicas/pfc/build/server/lib/jta.jar:/data/Practicas/pfc/build/server/lib/log4j-1.2.8.jar:/data/Practicas/pfc/build/server/lib/mysql-connector.jar:/data/Practicas/pfc/build/server/lib/odmg-3.0.jar:/data/Practicas/pfc/build/server/lib/openjms-client-0.7.6.1.jar:/data/Practicas/pfc/build/server/lib/xercesImpl.jar:/data/Practicas/pfc/build/server/lib/c3p0-0.8.4.5.jar, user.name=inggvf01, java.vm.specification.version=1.0, java.home=/usr/share/j2sdk1.4.2/jre, sun.arch.data.model=32, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.connection.url=jdbc:mysql://localhost/rmap_server, user.language=es, java.specification.vendor=Sun Microsystems Inc., hibernate.c3p0.max_size=15, hibernate.cglib.use_reflection_optimizer=true, java.vm.info=mixed mode, java.version=1.4.2, java.ext.dirs=/usr/share/j2sdk1.4.2/jre/lib/ext, sun.boot.class.path=/usr/share/j2sdk1.4.2/jre/lib/rt.jar:/usr/share/j2sdk1.4.2/jre/lib/i18n.jar:/usr/share/j2sdk1.4.2/jre/lib/sunrsasign.jar:/usr/share/j2sdk1.4.2/jre/lib/jsse.jar:/usr/share/j2sdk1.4.2/jre/lib/jce.jar:/usr/share/j2sdk1.4.2/jre/lib/charsets.jar:/usr/share/j2sdk1.4.2/jre/classes, java.vendor=Sun Microsystems Inc., file.separator=/, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, sun.cpu.isalist=}
17:31:30,245 DEBUG SessionFactoryObjectFactory:39 - initializing class SessionFactoryObjectFactory
17:31:30,255 DEBUG SessionFactoryObjectFactory:76 - registered: ff808081feb19c1200feb19c183d0000 (unnamed)
17:31:30,257 INFO SessionFactoryObjectFactory:82 - no JNDI name configured
17:31:30,257 DEBUG SessionFactoryImpl:196 - instantiated session factory
17:31:30,425 DEBUG SessionImpl:555 - opened session
17:31:30,437 DEBUG JDBCTransaction:37 - begin
17:31:30,439 DEBUG JDBCTransaction:41 - current autocommit status:false
17:31:30,446 DEBUG SessionImpl:1526 - find: from Plugin
17:31:30,503 DEBUG QueryTranslator:147 - compiling query
17:31:30,556 DEBUG SessionImpl:2242 - flushing session
17:31:30,557 DEBUG SessionImpl:2435 - Flushing entities and processing referenced collections
17:31:30,558 DEBUG SessionImpl:2776 - Processing unreferenced collections
17:31:30,559 DEBUG SessionImpl:2790 - Scheduling collection removes/(re)creates/updates
17:31:30,560 DEBUG SessionImpl:2266 - Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
17:31:30,564 DEBUG SessionImpl:2271 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
17:31:30,565 DEBUG SessionImpl:1814 - Dont need to execute flush
17:31:30,566 DEBUG QueryTranslator:199 - HQL: from Plugin
17:31:30,566 DEBUG QueryTranslator:200 - SQL: select from
17:31:30,568 DEBUG BatcherImpl:196 - about to open: 0 open PreparedStatements, 0 open ResultSets
17:31:30,576 DEBUG SQL:237 - select from
17:31:30,579 DEBUG BatcherImpl:241 - preparing statement
17:31:30,713 DEBUG JDBCExceptionReporter:36 - SQL Exception
java.sql.SQLException: Syntax error or access violation, message from server: "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: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 com.mchange.v2.sql.filter.FilterPreparedStatement.executeQuery(FilterPreparedStatement.java:68)
at com.mchange.v2.c3p0.impl.C3P0PooledConnection$2.executeQuery(C3P0PooledConnection.java:567)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:800)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:189)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:955)
at net.sf.hibernate.loader.Loader.list(Loader.java:946)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:846)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1543)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1520)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1512)
at org.rmap.pruebaHiber8.main(pruebaHiber8.java:41)
17:31:30,726 WARN JDBCExceptionReporter:38 - SQL Error: 1064, SQLState: 42000
17:31:30,727 ERROR JDBCExceptionReporter:46 - Syntax error or access violation, message from server: "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"
17:31:30,728 DEBUG BatcherImpl:203 - done closing: 0 open PreparedStatements, 0 open ResultSets
17:31:30,729 DEBUG BatcherImpl:261 - closing statement
17:31:30,732 DEBUG JDBCExceptionReporter:36 - SQL Exception
java.sql.SQLException: Syntax error or access violation, message from server: "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: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 com.mchange.v2.sql.filter.FilterPreparedStatement.executeQuery(FilterPreparedStatement.java:68)
at com.mchange.v2.c3p0.impl.C3P0PooledConnection$2.executeQuery(C3P0PooledConnection.java:567)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:800)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:189)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:955)
at net.sf.hibernate.loader.Loader.list(Loader.java:946)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:846)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1543)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1520)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1512)
at org.rmap.pruebaHiber8.main(pruebaHiber8.java:41)
17:31:30,733 WARN JDBCExceptionReporter:38 - SQL Error: 1064, SQLState: 42000
17:31:30,738 ERROR JDBCExceptionReporter:46 - Syntax error or access violation, message from server: "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"
17:31:30,762 ERROR JDBCExceptionReporter:38 - Could not execute query
java.sql.SQLException: Syntax error or access violation, message from server: "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: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 com.mchange.v2.sql.filter.FilterPreparedStatement.executeQuery(FilterPreparedStatement.java:68)
at com.mchange.v2.c3p0.impl.C3P0PooledConnection$2.executeQuery(C3P0PooledConnection.java:567)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:800)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:189)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:955)
at net.sf.hibernate.loader.Loader.list(Loader.java:946)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:846)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1543)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1520)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1512)
at org.rmap.pruebaHiber8.main(pruebaHiber8.java:41)
java.sql.SQLException: Syntax error or access violation, message from server: "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"
Name and version of the database you are using: Mysql 4.0.20
Hello,
I hace a parent clas Plugin, that has some artibutes anda group of getters/setters, an them I hace two child tables, Control and Sensor, that hace few methods, and use the inherited attributes. In the Control case, it have two new atributtes plus the Plugin atributes.
I use the mappind alrerade describued, and, to read o Control or Sensors with de HQL "from Control" or "from Sensor" and using the Plugin class with those, there is no problem... the problen went when I tried the HQL "form Plugin", that is translated by Hibernate in the SQL query "select from", and obviously, MySQL returns an error...
In the documentation this type of thing seems to work...