0

so i have a couple of @Entity 's that i'm testing out and the first two are create and dropped as the <property name="hibernate.hbm2ddl.auto">create</property> is in the xml hibernate cfg file but the last table is not being created and can´t find the reason, any suggestions ?

this is the last table:

        @Entity
    @Table(name="ETAPAS")
    public class Etapa {

        @Id
        @Column(name = "ID")
        @GeneratedValue(strategy = GenerationType.AUTO)
        private int id;
        private String origen, destino, fecha, hora, categoria, tipo;
        @Embedded
        private Puerto puerto;
        @Embedded
        private Mapa  mapa;

       //  setters &  getters 


@Embeddable
public class Mapa {


    @Column(name = "NOMBRE_MAPA")
    private String nombre;
    @Lob
    private byte[] imagen;  

       //  setters &  getters   



@Embeddable
public class Puerto {

    private int altura;
    @Column(name = "NOMBRE_PUERTO")
    private String nombre;

       //  setters &  getters 

and error:

Starting persistence 
nov 09, 2014 1:49:42 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
nov 09, 2014 1:49:42 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.6.Final}
nov 09, 2014 1:49:42 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.h2.Driver, hibernate.service.allow_crawling=false, hibernate.dialect=org.hibernate.dialect.H2Dialect, hibernate.max_fetch_depth=5, hibernate.format_sql=true, hibernate.generate_statistics=true, hibernate.connection.username=sa, hibernate.connection.url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE, hibernate.bytecode.use_reflection_optimizer=false, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=5}
nov 09, 2014 1:49:42 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
nov 09, 2014 1:49:42 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
nov 09, 2014 1:49:42 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
nov 09, 2014 1:49:42 PM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
nov 09, 2014 1:49:42 PM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
nov 09, 2014 1:49:42 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
nov 09, 2014 1:49:42 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/infoiii]
nov 09, 2014 1:49:42 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000046: Connection properties: {user=root}
nov 09, 2014 1:49:42 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000006: Autocommit mode: false
nov 09, 2014 1:49:42 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 5 (min=1)
nov 09, 2014 1:49:43 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
nov 09, 2014 1:49:43 PM org.hibernate.dialect.H2Dialect <init>
WARN: HHH000431: Unable to determine H2 database version, certain features may not work
nov 09, 2014 1:49:43 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
nov 09, 2014 1:49:43 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
nov 09, 2014 1:49:44 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000227: Running hbm2ddl schema export
Hibernate: 
    drop table CICLISTA if exists
nov 09, 2014 1:49:44 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: HHH000389: Unsuccessful: drop table CICLISTA if exists
nov 09, 2014 1:49:44 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: 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 'if exists' at line 1
Hibernate: 
    drop table ETAPAS if exists
nov 09, 2014 1:49:44 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: HHH000389: Unsuccessful: drop table ETAPAS if exists
nov 09, 2014 1:49:44 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: 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 'if exists' at line 1
Hibernate: 
    drop table USUARIOS_ADMON if exists
nov 09, 2014 1:49:44 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: HHH000389: Unsuccessful: drop table USUARIOS_ADMON if exists
nov 09, 2014 1:49:44 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: 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 'if exists' at line 1
Hibernate: 
    create table CICLISTA (
        numero integer generated by default as identity,
        equipo varchar(255),
        nacionalidad varchar(255),
        nombre varchar(255),
        primary key (numero)
    )
nov 09, 2014 1:49:44 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: HHH000389: Unsuccessful: create table CICLISTA (numero integer generated by default as identity, equipo varchar(255), nacionalidad varchar(255), nombre varchar(255), primary key (numero))
nov 09, 2014 1:49:44 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: 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 'generated by default as identity,
        equipo varchar(255),
        nacionali' at line 2
Hibernate: 
    create table ETAPAS (
        ID integer generated by default as identity,
        categoria varchar(255),
        destino varchar(255),
        fecha varchar(255),
        hora varchar(255),
        imagen blob,
        NOMBRE_MAPA varchar(255),
        origen varchar(255),
        altura integer not null,
        NOMBRE_PUERTO varchar(255),
        tipo varchar(255),
        primary key (ID)
    )
nov 09, 2014 1:49:44 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: HHH000389: Unsuccessful: create table ETAPAS (ID integer generated by default as identity, categoria varchar(255), destino varchar(255), fecha varchar(255), hora varchar(255), imagen blob, NOMBRE_MAPA varchar(255), origen varchar(255), altura integer not null, NOMBRE_PUERTO varchar(255), tipo varchar(255), primary key (ID))
nov 09, 2014 1:49:44 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: 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 'generated by default as identity,
        categoria varchar(255),
        destin' at line 2
Hibernate: 
    create table USUARIOS_ADMON (
        ID integer generated by default as identity,
        CONTRASEÑA varchar(255),
        USUARIO varchar(255),
        primary key (ID)
    )
nov 09, 2014 1:49:44 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: HHH000389: Unsuccessful: create table USUARIOS_ADMON (ID integer generated by default as identity, CONTRASEÑA varchar(255), USUARIO varchar(255), primary key (ID))
nov 09, 2014 1:49:44 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: 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 'generated by default as identity,
        CONTRASEÑA varchar(255),
        USUA' at line 2
nov 09, 2014 1:49:44 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000230: Schema export complete
Hibernate: 
    insert 
    into
        USUARIOS_ADMON
        (ID, CONTRASEÑA, USUARIO) 
    values
        (null, ?, ?)
Hibernate: 
    insert 
    into
        CICLISTA
        (numero, equipo, nacionalidad, nombre) 
    values
        (null, ?, ?, ?)
Hibernate: 
    insert 
    into
        ETAPAS
        (ID, categoria, destino, fecha, hora, imagen, NOMBRE_MAPA, origen, altura, NOMBRE_PUERTO, tipo) 
    values
        (null, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
nov 09, 2014 1:49:45 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 1146, SQLState: 42S02
nov 09, 2014 1:49:45 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Table 'infoiii.etapas' doesn't exist
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute statement
    at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:80)
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:211)
    at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:96)
    at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:58)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3032)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3558)
    at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:98)
    at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:490)
    at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:195)
    at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:179)
    at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:214)
    at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:324)
    at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:288)
    at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:194)
    at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:125)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:209)
    at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:194)
    at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
    at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:715)
    at org.hibernate.internal.SessionImpl.save(SessionImpl.java:707)
    at org.hibernate.internal.SessionImpl.save(SessionImpl.java:702)
    at com.uci.ubosque.modelo.UsuariosAdmonTester.main(UsuariosAdmonTester.java:48)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'infoiii.etapas' doesn't exist
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
    at com.mysql.jdbc.Util.getInstance(Util.java:384)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4232)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4164)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2615)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2776)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2838)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2334)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2262)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2246)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208)
9
  • When does the error show up? On start-up when the tables are created or when you're querying the table? Commented Nov 9, 2014 at 18:34
  • @John, i created a little tester where i create an obj. then call the sessionFactory and ... session.save(obj); here the error is thrown Commented Nov 9, 2014 at 18:47
  • Anything in the logs on start-up time? Commented Nov 9, 2014 at 18:50
  • 1
    question updated with console log Commented Nov 9, 2014 at 19:07
  • Did you notice the several errors at startup time? Commented Nov 9, 2014 at 19:07

2 Answers 2

4

Turns out my problem was in the Dialect in the hibernate.cfg.xml file

my config :

<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>

this fixed my problem:

<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
Sign up to request clarification or add additional context in comments.

2 Comments

This is why I never specify a dialect for Hibernate to use. If you are using Hibernate 4, it can select its own dialect based on metadata
Even without specifying the dialect gives problem.
0

The problem, according to this answer, is that you need to use GenerationType.IDENTITY with MySQL, not GenerationType.AUTO.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.