簡體   English   中英

Hibernate不會創建Table - Spring MVC

[英]Hibernate doesn't create Table - Spring MVC

我有春天項目,我正在使用休眠。 當我開始項目時,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會更新現有架構。

鏈接供參考。

簡單來說,

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.dialect”是否設置為MySQL5Dialect,以防您使用MySQL作為數據庫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM