java – Hibernate不会创建表 – Spring MVC
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – Hibernate不会创建表 – Spring MVC,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2234字,纯文字阅读大概需要4分钟。
内容图文
![java – Hibernate不会创建表 – Spring MVC](/upload/InfoBanner/zyjiaocheng/744/d28cebe7ec8e44ee9f30aaa5f150589c.jpg)
我有春天项目,我正在使用休眠.当我开始项目时,db没有变化.
我尝试了difrenf配置,但没有工作.
什么想法可能是错的?
Hibernate在servlet.xml中配置:
<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"
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"
xmlns:beans="http://www.springframework.org/schema/beans">
<context:component-scan base-package="com.springapp.mvc"/>
<!--Data source has the database information -->
<beans:bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<beans:property name="driverClassName" value="org.postgresql.Driver"/>
<beans:property name="url" value="jdbc:postgresql://localhost:5432/Praktyki"/>
<beans:property name="username" value="dbusersolsoft"/>
<beans:property name="password" value="dbpassSolsoft"/>
</beans:bean>
<!-- Session Factory -->
<beans:bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<beans:property name="dataSource" ref="dataSource"/>
<beans:property name="packagesToScan">
<value>com.springapp.mvc.model</value>
</beans:property>
<!--<beans:property name="showSql" value="true" />-->
<!--<beans:property name="generateDdl" value="true" />-->
<beans:property name="hibernateProperties">
<beans:props>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">false</prop>
</beans:props>
</beans:property>
</beans:bean>
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
解决方法:
使用
<prop key="hibernate.hbm2ddl.auto">create</prop>
根据文档,update会更新现有架构.
link供参考.
简单来说,
validate: validate the schema, makes no changes to the database.
update: update the schema.
create: creates the schema, destroying previous data.
create-drop: drop the schema at the end of the session.
auto : Automatically validates or exports schema DDL to the database when the SessionFactory is created
内容总结
以上是互联网集市为您收集整理的java – Hibernate不会创建表 – Spring MVC全部内容,希望文章能够帮你解决java – Hibernate不会创建表 – Spring MVC所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。
来源:【匿名】