Hello friends. I'm an experienced Java programmer, but never had used the hibernate, this is my first time with it.
I've got tired of searching solutions for my problem, and with no success. I hope some other can help me fix this problem.
I'm running JDK 5 in eclipse (no plugins), to build a J2SE server, that communicates with a MySQL 5, using InnoDB.
It throws a
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException, and says the syntax is incorrect. But the SQL comes as a lot of interrogation points.
Tryed a lot of configurations. Including putting the user and password in commas, but then it tells the username/password is incorrect. The problems is really freaking me out, because I can't read the SQL, and its not telling the real source of the error, just some Warnings and the Exceptions. The warnings and exceptions, due to appear order, are the following:
- WARNING: Could not obtain connection to query metadata
- com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: 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
- WARNING: SQL Error: 1064, SQLState: 42000
- SEVERE: 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
Hera are all the mapping and configuration XMLs, inside this quoting and code tags.
Quote:
hibernate.cfg.xmlCode:
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.connection.url">
jdbc:mysql://localhost/gprs?useUnicode=true
</property>
<property name="hibernate.connection.username">
hibernate
</property>
<property name="hibernate.connection.password">
hibernate
</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</property>
<!-- Condiguração do c3p0 -->
<property name="hibernate.c3p0.max_size">10</property>
<property name="hibernate.c3p0.min_size">2</property>
<property name="hibernate.c3p0.timeout">5000</property>
<property name="hibernate.c3p0.max_statements">10</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
<!-- Configurações de debug -->
<property name="hibernate.show_sql">true</property>
<property name="hibernate.generate_statistics">true</property>
<property name="hibernate.use_sql_comments">true</property>
<mapping resource="Usuario.hbm.xml"/>
<mapping resource="Servico.hbm.xml"/>
<mapping resource="Registro.hbm.xml"/>
<mapping resource="TipoRegistro.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Usuario.hbm.xmlCode:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.lhf.gprs.server.database.Usuario">
<id name="idUsuario">
<generator class="increment" />
</id>
<property name="usuario" />
<property name="senha" />
<property name="acesso" />
<many-to-one name="Servico_idServico" class="com.lhf.gprs.server.database.Servico" column="Servico_idServico" />
<set name="Registros" inverse="true">
<key column="Usuario_idUsuario" />
<one-to-many class="com.lhf.gprs.server.database.Registro" />
</set>
</class>
</hibernate-mapping>
Servico.hbm.xmlCode:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.lhf.gprs.server.database.Servico">
<id name="idServico">
<generator class="increment" />
</id>
<property name="nome" />
<set name="Usuarios" inverse="true">
<key column="Servico_idServico" />
<one-to-many class="com.lhf.gprs.server.database.Usuario" />
</set>
<set name="TiposRegistro" inverse="true">
<key column="Servico_idServico" />
<one-to-many class="com.lhf.gprs.server.database.TipoRegistro" />
</set>
</class>
</hibernate-mapping>
TipoRegistro.hbm.xmlCode:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.lhf.gprs.server.database.TipoRegistro">
<id name="idTipoRegistro">
<generator class="increment" />
</id>
<property name="nome" />
<many-to-one name="Servico_idServico" class="com.lhf.gprs.server.database.Servico" column="Servico_idServico" />
<set name="Registros" inverse="true">
<key column="TipoRegistro_idTipoRegistro" />
<one-to-many class="com.lhf.gprs.server.database.Registro" />
</set>
</class>
</hibernate-mapping>
Registro.hbm.xmlCode:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.lhf.gprs.server.database.Registro">
<id name="idRegistro">
<generator class="increment" />
</id>
<property name="dataHora" type="date" />
<property name="valor" />
<many-to-one name="Usuario_idUsuario" class="com.lhf.gprs.server.database.Usuario" column="Usuario_idUsuario" />
<many-to-one name="TipoRegistro_idTipoRegistro" class="com.lhf.gprs.server.database.TipoRegistro" column="TipoRegistro_idTipoRegistro" />
</class>
</hibernate-mapping>
This is my MySQL DB creating SQL:
Code:
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';
CREATE TABLE IF NOT EXISTS `gprs`.`Registro` (
`idRegistro` INT(11) NOT NULL AUTO_INCREMENT ,
`dataHora` DATETIME NOT NULL ,
`valor` VARCHAR(45) NOT NULL ,
`Usuario_idUsuario` INT(11) NOT NULL ,
`TipoRegistro_idTipoRegistro` INT(11) NOT NULL ,
PRIMARY KEY (`idRegistro`, `Usuario_idUsuario`, `TipoRegistro_idTipoRegistro`) ,
INDEX `fk_Registros_Usuario` (`Usuario_idUsuario` ASC) ,
INDEX `fk_Registros_TipoRegistro1` (`TipoRegistro_idTipoRegistro` ASC) ,
CONSTRAINT `fk_Registros_Usuario`
FOREIGN KEY (`Usuario_idUsuario` )
REFERENCES `gprs`.`Usuario` (`idUsuario` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Registros_TipoRegistro1`
FOREIGN KEY (`TipoRegistro_idTipoRegistro` )
REFERENCES `gprs`.`TipoRegistro` (`idTipoRegistro` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1
COLLATE = latin1_swedish_ci;
CREATE TABLE IF NOT EXISTS `gprs`.`Servico` (
`idServico` INT(11) NOT NULL AUTO_INCREMENT ,
`nome` VARCHAR(45) NOT NULL ,
PRIMARY KEY (`idServico`) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1
COLLATE = latin1_swedish_ci;
CREATE TABLE IF NOT EXISTS `gprs`.`TipoRegistro` (
`idTipoRegistro` INT(11) NOT NULL ,
`nome` VARCHAR(45) NOT NULL ,
`Servico_idServico` INT(11) NOT NULL ,
PRIMARY KEY (`idTipoRegistro`, `Servico_idServico`) ,
INDEX `fk_TipoRegistro_Servico1` (`Servico_idServico` ASC) ,
CONSTRAINT `fk_TipoRegistro_Servico1`
FOREIGN KEY (`Servico_idServico` )
REFERENCES `gprs`.`Servico` (`idServico` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1
COLLATE = latin1_swedish_ci;
CREATE TABLE IF NOT EXISTS `gprs`.`Usuario` (
`idUsuario` INT(11) NOT NULL AUTO_INCREMENT ,
`usuario` VARCHAR(45) NOT NULL ,
`senha` VARCHAR(45) NOT NULL ,
`access` INT(11) NOT NULL DEFAULT 0 ,
`Servico_idServico` INT(11) NOT NULL ,
PRIMARY KEY (`idUsuario`, `Servico_idServico`) ,
INDEX `fk_Usuario_Servico1` (`Servico_idServico` ASC) ,
CONSTRAINT `fk_Usuario_Servico1`
FOREIGN KEY (`Servico_idServico` )
REFERENCES `gprs`.`Servico` (`idServico` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1
COLLATE = latin1_swedish_ci;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
Following the java test code:
Code:
package com.lhf.gprs.server.database;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class Teste {
public static void main(String[] args) {
Session sessao = new Configuration().configure().buildSessionFactory().openSession(); //Opening session - Throws exception
Transaction transaction = sessao.beginTransaction(); //Init transaction - Throws exception due to above exception
Usuario usuario = new Usuario();
usuario.setUsuario("teste");
usuario.setSenha("senha");
usuario.setAcesso(0);
usuario.setServico_idServico(1);
sessao.save(usuario);
transaction.commit();
sessao.close();
}
}
And here is the stdout with all INFOs, WARNINGS, SEVERE and EXCEPTIONs stack trace:
Quote:
24-Set-09 3:57:58 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.3.2.GA
24-Set-09 3:57:59 org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
24-Set-09 3:57:59 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : javassist
24-Set-09 3:57:59 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
24-Set-09 3:57:59 org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
24-Set-09 3:57:59 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
24-Set-09 3:57:59 org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : Usuario.hbm.xml
24-Set-09 3:57:59 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: com.lhf.gprs.server.database.Usuario -> Usuario
24-Set-09 3:57:59 org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : Servico.hbm.xml
24-Set-09 3:57:59 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: com.lhf.gprs.server.database.Servico -> Servico
24-Set-09 3:57:59 org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : Registro.hbm.xml
24-Set-09 3:57:59 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: com.lhf.gprs.server.database.Registro -> Registro
24-Set-09 3:57:59 org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : TipoRegistro.hbm.xml
24-Set-09 3:57:59 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: com.lhf.gprs.server.database.TipoRegistro -> TipoRegistro
24-Set-09 3:57:59 org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
24-Set-09 3:57:59 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: com.lhf.gprs.server.database.Usuario.Registros -> Registro
24-Set-09 3:57:59 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: com.lhf.gprs.server.database.Servico.Usuarios -> Usuario
24-Set-09 3:57:59 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: com.lhf.gprs.server.database.Servico.TiposRegistro -> TipoRegistro
24-Set-09 3:57:59 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: com.lhf.gprs.server.database.TipoRegistro.Registros -> Registro
24-Set-09 3:57:59 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
24-Set-09 3:57:59 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
24-Set-09 3:57:59 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
24-Set-09 3:57:59 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/gprs?useUnicode=true
24-Set-09 3:57:59 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=hibernate, password=****}
24-Set-09 3:58:04 org.hibernate.cfg.SettingsFactory buildSettings
WARNING: Could not obtain connection to query metadata
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: 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.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3277)
at com.mysql.jdbc.Connection.configureClientCharacterSet(Connection.java:2525)
at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:4139)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2789)
at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(libgcj.so.90)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:133)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:111)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2119)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2115)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1339)
at com.lhf.gprs.server.database.Teste.main(Teste.java:10)
24-Set-09 3:58:05 org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQLDialect
24-Set-09 3:58:05 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
24-Set-09 3:58:05 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
24-Set-09 3:58:05 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
24-Set-09 3:58:05 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
24-Set-09 3:58:05 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: disabled
24-Set-09 3:58:05 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
24-Set-09 3:58:05 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
24-Set-09 3:58:05 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximum outer join fetch depth: 2
24-Set-09 3:58:05 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
24-Set-09 3:58:05 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: enabled
24-Set-09 3:58:05 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
24-Set-09 3:58:05 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
24-Set-09 3:58:05 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
24-Set-09 3:58:05 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
24-Set-09 3:58:05 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
24-Set-09 3:58:05 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
24-Set-09 3:58:05 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
24-Set-09 3:58:05 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
24-Set-09 3:58:05 org.hibernate.cfg.SettingsFactory createRegionFactory
INFO: Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
24-Set-09 3:58:05 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
24-Set-09 3:58:05 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
24-Set-09 3:58:05 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
24-Set-09 3:58:05 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: enabled
24-Set-09 3:58:05 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
24-Set-09 3:58:05 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
24-Set-09 3:58:05 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
24-Set-09 3:58:05 org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
24-Set-09 3:58:05 org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
24-Set-09 3:58:05 org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 1064, SQLState: 42000
24-Set-09 3:58:05 org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: 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
Exception in thread "main" org.hibernate.exception.SQLGrammarException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:142)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:85)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1354)
at com.lhf.gprs.server.database.Teste.main(Teste.java:11)
Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: 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.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3277)
at com.mysql.jdbc.Connection.configureClientCharacterSet(Connection.java:2525)
at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:4139)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2789)
at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(libgcj.so.90)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:133)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
...5 more
Libs included in project:
- hibernate3.jar
- antlr-2.7.6.jar
- commons-collections-3.1.jar
- dom4j-1.6.1.jar
- javassist-3.9.0.GA.jar
- jta-1.1.jar
- slf4j-api-1.5.8.jar
- slf4j-jdk14-1.5.8.jar
- c3p0-0.9.1.jar
- jdbc2_0-stdext.jar
- log4j-1.2.9.jar
- mysql-connector-java-5.0.8-bin.jar
- ant-contrib.jar
- aspectjrt.jar
- aspecttools.jar
- cglib-2.2.jar
- commons-logging.jar
- ehcache-1.2.3.jar
Thank you for the attention.
Any comments that could help me will be appreciated.