首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Hibernate不创建Table - Spring MVC

Hibernate不创建Table - Spring MVC
EN

Stack Overflow用户
提问于 2014-02-13 20:30:31
回答 3查看 10.8K关注 0票数 3

我有一个spring项目,我正在使用hibernate。当我启动项目时,db没有变化。

我尝试过difrenf配置,但都不起作用。

有什么想法可能是错的吗?

Hibernate在servlet.xml中配置:

代码语言:javascript
运行
复制
<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" />

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-02-13 20:59:12

使用

代码语言:javascript
运行
复制
<prop key="hibernate.hbm2ddl.auto">create</prop>

根据文档,update将更新现有架构。

link以供参考。

简而言之,

代码语言:javascript
运行
复制
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
票数 6
EN

Stack Overflow用户

发布于 2014-02-13 20:33:41

在开始项目之前创建一次项目,然后继续。大多数应用程序在启动时都假定模式是先验存在的。

票数 1
EN

Stack Overflow用户

发布于 2018-03-11 00:09:39

如果您正确地遵循了所有步骤,但仍然收到错误,请检查"hibernate.dialect“是否设置为MySQL5Dialect,以防您使用MySQL作为数据库。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21754326

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档