Schema is not created automatically if Hibernate4 and spring4 for mysql do not exist

A schema is not created automatically, if it does not exist, how to solve it, if the database name exists, since the tables are created automatically, but the schema does not exist, which means that the schema was not created at runtime, how to do it.

sleep mode properties

hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
hibernate.hbm2ddl.auto=create-update ** i use these keyword seperately also //create or//update**



**xml configuration**

<bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="com.testing.domain" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
                </prop>
            </props>
        </property>
    </bean>  
+4
source share
4 answers

use this in your code, it discards the current circuit and creates a new one.

           <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto.create-drop}</prop>
+2
source

There is no value create-updatefor the property hibernate.hbm2ddl.auto. All possible values

  • validate
  • update
  • create
  • create a fall

. create ,

0

import.sql.

import.sql :

/*create database at first time*/ 
CREATE SCHEMA your-database-name;

hibernate.cfg.xml :

<hibernate-configuration>
    <session-factory>
       ...
       ...
       <property name="hbm2ddl.import_files">import.sql</property>
       ...
       ...
    </session-factory>
</hibernate-configuration>

, , hibernate db.

hibernate.hbm2ddl.auto , (options are validate, create, update or create-drop)

"none", .

<prop key="hibernate.hbm2ddl.auto">create</prop>

create sessionFactory .

create-drop , , sessionFactory.

: , .

update: .

0

select value hibernate.hbm2ddl.auto create. , . , StackOverflow select hibernate.hbm2ddl.auto, , select "hibernate.hbm2ddl.auto".

<beans:bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <beans:property name="dataSource" ref="databaseDataSource" />
    <beans:property name="hibernateProperties">
        <beans:props>
            <beans:prop key="hibernate.hbm2ddl.auto">select</beans:prop>
        </beans:props>
    </beans:property>
</beans:bean>

In case someone has additional inputs to choose an option. Share please.

0
source

All Articles