Hibernate不会创建Table - Spring MVC [英] Hibernate doesn't create Table - Spring MVC

查看:103
本文介绍了Hibernate不会创建Table - Spring MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用hibernate的春天项目。当我启动项目时,数据库没有变化。

I have spring project where I'm using hibernate. When I start project there is no change in db.

我尝试使用difrenf配置,但没有使用。

I try difrenf configurations but nothings worked.

想法什么可能是错误的?

Any ideas what can be wrong?

Hibernate在servlet.xml中配置:

Hibernate is configure in 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>

根据文档,更新会更新现有模式。

As per the documentation, update updates the existing schema.

链接以供参考。

简而言之,

In brief,

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

这篇关于Hibernate不会创建Table - Spring MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆