Question

I am using MySQL5 and my applicationContext.xml has the following beans:

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost:3306/ems" />
    <property name="username" value="root" />
    <property name="password" value="admin" />
</bean>

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hbm2ddl.auto">create</prop>
            <prop key="connection.url">jdbc:mysql://localhost:3306/ems</prop>
            <prop key="connection.username">root</prop>
            <prop key="connection.password">admin</prop>
            <prop key="connection.driver_class">com.mysql.jdbc.Driver</prop>
        </props>
    </property>
    <property name="mappingDirectoryLocations" value="/WEB-INF/resources/mappings" />
</bean>

I have created a schema named "ems" with MySQL Workbench, but when I deploy the application in console, it prints:

01:22:54,823 INFO  [org.hibernate.cfg.Environment] (MSC service thread 1-2) HHH000206: hibernate.properties not found
01:22:54,827 INFO  [org.hibernate.cfg.Environment] (MSC service thread 1-2) HHH000021: Bytecode provider name : javassist
01:22:54,841 INFO  [org.hibernate.cfg.Configuration] (MSC service thread 1-2) HHH000220: Reading mappings from file: C:\Development\JBoss-AS-7.1.0.Final\standalone\tmp\vfs\tempf3cbb10675b49730\EMSApplication.war-43fc183fcacfc03f\WEB-INF\resources\mappings\User.hbm.xml
01:22:56,884 INFO  [org.hibernate.dialect.Dialect] (MSC service thread 1-2) HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
01:22:56,892 INFO  [org.hibernate.engine.jdbc.internal.LobCreatorBuilder] (MSC service thread 1-2) HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
01:22:56,901 INFO  [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] (MSC service thread 1-2) HHH000399: Using default transaction strategy (direct JDBC transactions)
01:22:56,908 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (MSC service thread 1-2) HHH000397: Using ASTQueryTranslatorFactory

There is no exception in console. But in the schema ems the tables are empty, meaning no table has been created.

The User.hbm.xml resides in the specified location and which is:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  "http://www.jboss.org/dtd/hibernate/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="app.dev.ems.data.model.User" table="USER">
        <id name="id" column="ID">
            <generator class="native"/>         
        </id>
    </class>
</hibernate-mapping>

Also the User.java is present.

I am using hibernate-core-4.1.1.Final with spring-orm-3.1.1.RELEASE.

What I am doing wrong?

Was it helpful?

Solution

I have made a mistake: The <prop key="hbm2ddl.auto">create</prop> should be <prop key="hibernate.hbm2ddl.auto">create</prop>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top