Generate DDL JPA com Hibernate

1 resposta
F

Estou tentando configurar minha aplicação para criar as tabelas no banco MySQL caso nao exista, ao iniciar a aplicação, mas não esta criando nem disparando erros.

Segue o meu applicationContext do Spring

<tx:annotation-driven transaction-manager="txManager" />
    
    <bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>
	
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="myDataSource" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="${jpa.show.sql}" />
                <property name="generateDdl" value="${jpa.generateDdl}" /> 
            </bean>
        </property>
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.dialect">${jpa.dialect}</prop>
                <prop key="hibernate.format_sql">${jpa.format_sql}</prop>
            </props>
        </property>
    </bean>

    <bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${db.driverClassName}" />
        <property name="url" value="${db.url}" />
        <property name="username" value="${db.username}" />
        <property name="password" value="${db.password}" />
    </bean>
	
    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
db.driverClassName=com.mysql.jdbc.Driver
db.url=jdbc:mysql://localhost/test
db.username=root
db.password=123456
jpa.show.sql=true
jpa.format_sql=true
jpa.dialect=org.hibernate.dialect.MySQLInnoDBDialect
jpa.generateDdl=true

O valor de jpa.generateDdl é true.

O que esta errado na configuração, estou utilizando o MySQL 5.6

1 Resposta

F

Olhei o log novamente e esta dando o seguinte erro

ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - Unsuccessful: create table role (id integer not null auto_increment, descricao varchar(255), primary key (id)) type=InnoDB 1206 [localhost-startStop-1] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - 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 1207 [localhost-startStop-1] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - Unsuccessful: create table usuario (id integer not null auto_increment, ativo bit not null, nome varchar(255), password varchar(20), username varchar(50), primary key (id), unique (username)) type=InnoDB 1207 [localhost-startStop-1] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - 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 1207 [localhost-startStop-1] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - Unsuccessful: create table usuarioRole (idUsuario integer not null, idRole integer not null) type=InnoDB 1207 [localhost-startStop-1] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - 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 1207 [localhost-startStop-1] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - Unsuccessful: alter table usuarioRole add index FK3112A0C45D102DD7 (idUsuario), add constraint FK3112A0C45D102DD7 foreign key (idUsuario) references usuario (id) 1207 [localhost-startStop-1] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - Table 'test.usuariorole' doesn't exist 1208 [localhost-startStop-1] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - Unsuccessful: alter table usuarioRole add index FK3112A0C48FBF6351 (idRole), add constraint FK3112A0C48FBF6351 foreign key (idRole) references role (id) 1208 [localhost-startStop-1] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - Table 'test.usuariorole' doesn't exist

Como eu tiro esse type=InnoDB da execucao das querys?

Criado 13 de maio de 2013
Ultima resposta 13 de mai. de 2013
Respostas 1
Participantes 1