Problemas com tabelas geradas pelo hibernate

5 respostas
chal10

Ao fazer o exercícios: configurando e gerando o schema do banco da apostila da caelum fj21 o Meu hibernate esta gerando a seguinte tabela:

create table Produto (
        id bigint not null auto_increment,
        descricao varchar(255),
        nome varchar(255),
        preco double precision not null,
        primary key (id)
    ) type=InnoDB
Mas meu SGBD mysql não esta aceitando o tipo: type=InnoDB, pois consigo criar essa tabela no mysql diretamente sem o paramatro type=InnoDB , Com isso meu hibernate não consegue criar essa tabela no meu mysql. Como corrigir isso no meu hibernate ou no meu mysql? qual é a forma correta(padrão) para criar tabelas, com tipo ou sem tipo? Mensagem de erro no Console:
09:41:11  INFO [Version             ] Hibernate Annotations 3.5.0-Final
09:41:11  INFO [Environment         ] Hibernate 3.5.0-Final
09:41:11  INFO [Environment         ] loaded properties from resource hibernate.properties: {hibernate.connection.username=root, hibernate.connection.password=****, hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect, hibernate.show_sql=true, hibernate.connection.url=jdbc:mysql://localhost/test, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.format_sql=true}
09:41:11  INFO [Environment         ] Bytecode provider name : javassist
09:41:11  INFO [Environment         ] using JDK 1.4 java.sql.Timestamp handling
09:41:11  INFO [Version             ] Hibernate Commons Annotations 3.2.0.Final
09:41:11  INFO [Dialect             ] Using dialect: org.hibernate.dialect.MySQLInnoDBDialect
09:41:11  INFO [AnnotationBinder    ] Binding entity from annotated class: br.com.caelum.hibernate.Produto
09:41:11  INFO [EntityBinder        ] Bind entity br.com.caelum.hibernate.Produto on table Produto
09:41:11  INFO [AnnotationConfiguration] Hibernate Validator not found: ignoring
09:41:11  INFO [SchemaExport        ] Running hbm2ddl schema export
09:41:11  INFO [SchemaExport        ] exporting generated schema to database
09:41:11  INFO [DriverManagerConnectionProvider] Using Hibernate built-in connection pool (not for production use!)
09:41:11  INFO [DriverManagerConnectionProvider] Hibernate connection pool size: 20
09:41:11  INFO [DriverManagerConnectionProvider] autocommit mode: false
09:41:11  INFO [DriverManagerConnectionProvider] using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/test
09:41:11  INFO [DriverManagerConnectionProvider] connection properties: {user=root, password=****}

    drop table if exists Produto

    create table Produto (
        id bigint not null auto_increment,
        descricao varchar(255),
        nome varchar(255),
        preco double precision not null,
        primary key (id)
    ) type=InnoDB
09:41:11 ERROR [SchemaExport        ] Unsuccessful: create table Produto (id bigint not null auto_increment, descricao varchar(255), nome varchar(255), preco double precision not null, primary key (id)) type=InnoDB
09:41:11 ERROR [SchemaExport        ] 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 'type=InnoDB' at line 1
09:41:11  INFO [SchemaExport        ] schema export complete
09:41:11  INFO [DriverManagerConnectionProvider] cleaning up connection pool: jdbc:mysql://localhost/test

Aguardo respostas, desde já gradeço.

5 Respostas

romarcio

Troca o dialeto do Hibernate para: hibernate.dialect=org.hibernate.dialect.MySQL5Dialect ou hibernate.dialect=org.hibernate.dialect.MySQLDialect

chal10

usando: hibernate.dialect = org.hibernate.dialect.MySQLDialect , deu esse erro.

11:21:49 INFO [Version ] Hibernate Annotations 3.5.0-Final 11:21:49 INFO [Environment ] Hibernate 3.5.0-Final 11:21:49 INFO [Environment ] loaded properties from resource hibernate.properties: {hibernate.connection.username=root, hibernate.connection.password=****, hibernate.dialect=org.hibernate.dialect.MySQLDialect , hibernate.show_sql=true, hibernate.connection.url=jdbc:mysql://localhost/test, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.format_sql=true} 11:21:49 INFO [Environment ] Bytecode provider name : javassist 11:21:49 INFO [Environment ] using JDK 1.4 java.sql.Timestamp handling 11:21:49 INFO [Version ] Hibernate Commons Annotations 3.2.0.Final Exception in thread "main" org.hibernate.HibernateException: Dialect class not found: org.hibernate.dialect.MySQLDialect at org.hibernate.dialect.Dialect.instantiateDialect(Dialect.java:311) at org.hibernate.dialect.Dialect.getDialect(Dialect.java:300) at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:121) at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:91) at br.com.caelum.hibernate.GeraTabelas.main(GeraTabelas.java:12)

Usando: hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

11:24:38 INFO [Version ] Hibernate Annotations 3.5.0-Final 11:24:38 INFO [Environment ] Hibernate 3.5.0-Final 11:24:38 INFO [Environment ] loaded properties from resource hibernate.properties: {hibernate.connection.username=root, hibernate.connection.password=****, hibernate.dialect=org.hibernate.dialect.MySQL5Dialect , hibernate.show_sql=true, hibernate.connection.url=jdbc:mysql://localhost/test, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.format_sql=true} 11:24:38 INFO [Environment ] Bytecode provider name : javassist 11:24:38 INFO [Environment ] using JDK 1.4 java.sql.Timestamp handling 11:24:38 INFO [Version ] Hibernate Commons Annotations 3.2.0.Final Exception in thread "main" org.hibernate.HibernateException: Dialect class not found: org.hibernate.dialect.MySQL5Dialect at org.hibernate.dialect.Dialect.instantiateDialect(Dialect.java:311) at org.hibernate.dialect.Dialect.getDialect(Dialect.java:300) at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:121) at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:91) at br.com.caelum.hibernate.GeraTabelas.main(GeraTabelas.java:12)

chal10

depois de criar a tabela sem o parametro de tipo, meu hibernate inseriu no banco com sucesso e meu cosole informou:

11:40:50 INFO [Version ] Hibernate Annotations 3.5.0-Final 11:40:50 INFO [Environment ] Hibernate 3.5.0-Final 11:40:50 INFO [Environment ] loaded properties from resource hibernate.properties: {hibernate.connection.username=root, hibernate.connection.password=****, hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect, hibernate.show_sql=true, hibernate.connection.url=jdbc:mysql://localhost/fj21, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.format_sql=true} 11:40:50 INFO [Environment ] Bytecode provider name : javassist 11:40:50 INFO [Environment ] using JDK 1.4 java.sql.Timestamp handling 11:40:50 INFO [Version ] Hibernate Commons Annotations 3.2.0.Final 11:40:50 INFO [HibernateSearchEventListenerRegister] Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled. 11:40:50 INFO [AnnotationBinder ] Binding entity from annotated class: br.com.caelum.hibernate.Produto 11:40:51 INFO [EntityBinder ] Bind entity br.com.caelum.hibernate.Produto on table Produto 11:40:51 INFO [AnnotationConfiguration] Hibernate Validator not found: ignoring 11:40:51 INFO [DriverManagerConnectionProvider] Using Hibernate built-in connection pool (not for production use!) 11:40:51 INFO [DriverManagerConnectionProvider] Hibernate connection pool size: 20 11:40:51 INFO [DriverManagerConnectionProvider] autocommit mode: false 11:40:51 INFO [DriverManagerConnectionProvider] using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/fj21 11:40:51 INFO [DriverManagerConnectionProvider] connection properties: {user=root, password=****} 11:40:51 INFO [SettingsFactory ] RDBMS: MySQL, version: 5.5.12 11:40:51 INFO [SettingsFactory ] JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.18 ( Revision: [email removido]-20110930151701-jfj14ddfq48ifkfq ) 11:40:51 INFO [Dialect ] Using dialect: org.hibernate.dialect.MySQLInnoDBDialect 11:40:51 INFO [TransactionFactoryFactory] Using default transaction strategy (direct JDBC transactions) 11:40:51 INFO [TransactionManagerLookupFactory] No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended) 11:40:51 INFO [SettingsFactory ] Automatic flush during beforeCompletion(): disabled 11:40:51 INFO [SettingsFactory ] Automatic session close at end of transaction: disabled 11:40:51 INFO [SettingsFactory ] JDBC batch size: 15 11:40:51 INFO [SettingsFactory ] JDBC batch updates for versioned data: disabled 11:40:51 INFO [SettingsFactory ] Scrollable result sets: enabled 11:40:51 INFO [SettingsFactory ] JDBC3 getGeneratedKeys(): enabled 11:40:51 INFO [SettingsFactory ] Connection release mode: auto 11:40:51 INFO [SettingsFactory ] Maximum outer join fetch depth: 2 11:40:51 INFO [SettingsFactory ] Default batch fetch size: 1 11:40:51 INFO [SettingsFactory ] Generate SQL with comments: disabled 11:40:51 INFO [SettingsFactory ] Order SQL updates by primary key: disabled 11:40:51 INFO [SettingsFactory ] Order SQL inserts for batching: disabled 11:40:51 INFO [SettingsFactory ] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory 11:40:51 INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory 11:40:51 INFO [SettingsFactory ] Query language substitutions: {} 11:40:51 INFO [SettingsFactory ] JPA-QL strict compliance: disabled 11:40:51 INFO [SettingsFactory ] Second-level cache: enabled 11:40:51 INFO [SettingsFactory ] Query cache: disabled 11:40:51 INFO [SettingsFactory ] Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory 11:40:51 INFO [SettingsFactory ] Optimize cache for minimal puts: disabled 11:40:51 INFO [SettingsFactory ] Structured second-level cache entries: disabled 11:40:51 INFO [SettingsFactory ] Echoing all SQL to stdout 11:40:51 INFO [SettingsFactory ] Statistics: disabled 11:40:51 INFO [SettingsFactory ] Deleted entity synthetic identifier rollback: disabled 11:40:51 INFO [SettingsFactory ] Default entity-mode: pojo 11:40:51 INFO [SettingsFactory ] Named query checking : enabled 11:40:51 INFO [SettingsFactory ] Check Nullability in Core (should be disabled when Bean Validation is on): enabled 11:40:51 INFO [SessionFactoryImpl ] building session factory 11:40:51 INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured Hibernate: insert into Produto (descricao, nome, preco) values (?, ?, ?) ID do produto: 2

romarcio

chal10:
usando: hibernate.dialect = org.hibernate.dialect.MySQLDialect , deu esse erro.

11:21:49 INFO [Version ] Hibernate Annotations 3.5.0-Final 11:21:49 INFO [Environment ] Hibernate 3.5.0-Final 11:21:49 INFO [Environment ] loaded properties from resource hibernate.properties: {hibernate.connection.username=root, hibernate.connection.password=****, hibernate.dialect=org.hibernate.dialect.MySQLDialect , hibernate.show_sql=true, hibernate.connection.url=jdbc:mysql://localhost/test, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.format_sql=true} 11:21:49 INFO [Environment ] Bytecode provider name : javassist 11:21:49 INFO [Environment ] using JDK 1.4 java.sql.Timestamp handling 11:21:49 INFO [Version ] Hibernate Commons Annotations 3.2.0.Final Exception in thread "main" org.hibernate.HibernateException: Dialect class not found: org.hibernate.dialect.MySQLDialect at org.hibernate.dialect.Dialect.instantiateDialect(Dialect.java:311) at org.hibernate.dialect.Dialect.getDialect(Dialect.java:300) at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:121) at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:91) at br.com.caelum.hibernate.GeraTabelas.main(GeraTabelas.java:12)

Usando: hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

11:24:38 INFO [Version ] Hibernate Annotations 3.5.0-Final 11:24:38 INFO [Environment ] Hibernate 3.5.0-Final 11:24:38 INFO [Environment ] loaded properties from resource hibernate.properties: {hibernate.connection.username=root, hibernate.connection.password=****, hibernate.dialect=org.hibernate.dialect.MySQL5Dialect , hibernate.show_sql=true, hibernate.connection.url=jdbc:mysql://localhost/test, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.format_sql=true} 11:24:38 INFO [Environment ] Bytecode provider name : javassist 11:24:38 INFO [Environment ] using JDK 1.4 java.sql.Timestamp handling 11:24:38 INFO [Version ] Hibernate Commons Annotations 3.2.0.Final Exception in thread "main" org.hibernate.HibernateException: Dialect class not found: org.hibernate.dialect.MySQL5Dialect at org.hibernate.dialect.Dialect.instantiateDialect(Dialect.java:311) at org.hibernate.dialect.Dialect.getDialect(Dialect.java:300) at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:121) at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:91) at br.com.caelum.hibernate.GeraTabelas.main(GeraTabelas.java:12)

:?: Que estranho.
Aqui a lista de todos os dialetos:


chal10
Funcionouuuuuuuuuuuuu!!!!! hehehe valeu!
18:47:14  INFO [Version             ] Hibernate Annotations 3.5.0-Final
18:47:14  INFO [Environment         ] Hibernate 3.5.0-Final
18:47:14  INFO [Environment         ] loaded properties from resource hibernate.properties: {hibernate.connection.username=root, hibernate.connection.password=****, hibernate.dialect=org.hibernate.dialect.MySQLDialect, hibernate.show_sql=true, hibernate.connection.url=jdbc:mysql://localhost/fj21, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.format_sql=true}
18:47:14  INFO [Environment         ] Bytecode provider name : javassist
18:47:14  INFO [Environment         ] using JDK 1.4 java.sql.Timestamp handling
18:47:14  INFO [Version             ] Hibernate Commons Annotations 3.2.0.Final
18:47:14  INFO [Dialect             ] Using dialect: org.hibernate.dialect.MySQLDialect
18:47:14  INFO [AnnotationBinder    ] Binding entity from annotated class: br.com.caelum.hibernate.Produto
18:47:14  INFO [EntityBinder        ] Bind entity br.com.caelum.hibernate.Produto on table Produto
18:47:14  INFO [AnnotationConfiguration] Hibernate Validator not found: ignoring
18:47:14  INFO [SchemaExport        ] Running hbm2ddl schema export
18:47:14  INFO [SchemaExport        ] exporting generated schema to database
18:47:14  INFO [DriverManagerConnectionProvider] Using Hibernate built-in connection pool (not for production use!)
18:47:14  INFO [DriverManagerConnectionProvider] Hibernate connection pool size: 20
18:47:14  INFO [DriverManagerConnectionProvider] autocommit mode: false
18:47:14  INFO [DriverManagerConnectionProvider] using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/fj21
18:47:14  INFO [DriverManagerConnectionProvider] connection properties: {user=root, password=****}

    drop table if exists Produto

    create table Produto (
        id bigint not null auto_increment,
        descricao varchar(255),
        nome varchar(255),
        preco double precision not null,
        primary key (id)
    )
18:47:15  INFO [SchemaExport        ] schema export complete
18:47:15  INFO [DriverManagerConnectionProvider] cleaning up connection pool: jdbc:mysql://localhost/fj21

Agora até eu achei estranho, fiz exatamente isso como mostrado acima no primeiro erro!!! ahushuahus

Criado 7 de janeiro de 2012
Ultima resposta 7 de jan. de 2012
Respostas 5
Participantes 2