【问题标题】:hibernate auto create won`t work with spring休眠自动创建不适用于弹簧
【发布时间】:2011-12-30 14:45:41
【问题描述】:

你好,我有一个奇怪的问题。我配置了spring + hibernate。我正在使用注释配置,但是当我启动/重新发布/重新启动服务器时,hibernate 不想创建我的数据库结构:(

这是我来自 root-context.xml 的配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

<!-- Root Context: defines shared resources visible to all other web components -->

<!-- Datasource configration -->
<bean id="luxpolDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost:3306/luxpol" />
    <property name="username" value="user" />
    <property name="password" value="pass" />
</bean>

<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="luxpolDataSource" />
    <property name="packagesToScan" value="com.fixus.luxpol.bean" />
    <property name="annotatedClasses">
        <list>
            <value>com.fixus.luxpol.bean.House</value>
            <value>com.fixus.luxpol.bean.Photo</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>                         
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
            <prop key="hibernate.format_sql">true</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.hbm2dll.auto">create</prop>
        </props>
    </property>
</bean>

<mvc:annotation-driven />
<context:component-scan base-package="com.fixus.luxpol" />
<context:component-scan base-package="com.fixus.luxpol.bean" />

我不知道怎么了:/

【问题讨论】:

    标签: hibernate spring spring-mvc


    【解决方案1】:

    该属性名为hbm2ddl.auto,而不是hbm2dll.auto。 DDL 表示数据定义语言。 DLL 表示动态链接库

    【讨论】:

      猜你喜欢
      • 2016-11-04
      • 2020-03-13
      • 1970-01-01
      • 1970-01-01
      • 2017-11-11
      • 2011-08-09
      • 2012-01-22
      • 2015-12-14
      • 1970-01-01
      相关资源
      最近更新 更多