spring4配置hibernate4 hibernate.hbm2ddl.auto无效
我在Spring文件里配置了hibernate4,但是hibernate.hbm2ddl.auto没有自己创建schema,请闻如何解决
配置文件如下
<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.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
">
<context:component-scan base-package="com.springapp.mvc"/>
<mvc:annotation-driven />
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/education?characterEncoding=utf8" />
<property name="user" value="root" />
<property name="password" value="" />
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="20" />
<property name="initialPoolSize" value="2" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.springapp.model"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
配置文件如下
<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.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
">
<context:component-scan base-package="com.springapp.mvc"/>
<mvc:annotation-driven />
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/education?characterEncoding=utf8" />
<property name="user" value="root" />
<property name="password" value="" />
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="20" />
<property name="initialPoolSize" value="2" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.springapp.model"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
...全文
相关推荐
详解hibernate自动创建表的配置
详解hibernate自动创建表的配置 配置自动创建表: update//首次创建项目时用,项目稳定后一般注释这里有4个值: update:表示自动根据model对象来更新表结构,启动hibernate时会自动检查数据库,如果缺少表,则自动建表;如果表里缺少列,则自动添加列。 还有其他的参数: create:启动hibernate时,自动删除原来的表,新建所有的表,所以每次启动后的以前数据都会丢失。 create-drop:启动hibernate时,自动创建表,程序关闭时,自动把相应的表都删除。所以程序
Spring中spring.jpa.hibernate.ddl-auto属性的工作原理
在Spring Boot应用开发中,与数据库交互是常见的需求。JPA(Java Persistence API) 提供了一种方便的方式来管理对象与数据库表之间的映射。而属性是Spring Data JPA 用于指定如何管理数据库模式的重要配置。通过设置不同的值,可以控制Hibernate在应用启动时如何对数据库模式进行操作,例如创建、更新或验证表结构等。
集成springmvc spring hibernate的配置
集成springmvc spring hibernate的配置过程 文档
springboot集成hibernate
springboot集成hibernate无jpa,在dao中使用SessionFactory操作数据库
spring mvc + hibernate4整合文档
Spring2.5+Struts2+Hibernate3的整合跟Spring2.5+Struts2+Jpa的整合过程。


Web 开发
