2014-02-13 100 views
3

我有春季項目,我使用休眠。當我啓動項目時,db中沒有變化。休眠不創建表 - 春天MVC

我嘗試difrenf配置,但nothings工作。

任何想法可能是錯的?

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" /> 

+0

你試過了嗎?' –

+0

@KevinBowersox錯誤的語法,我不能用 –

回答

5

使用

<prop key="hibernate.hbm2ddl.auto">create</prop> 

按照文件,更新更新現有的架構。

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 
1

創建項目,一旦你開始項目之前,繼續前進。大多數應用程序假定架構在啓動時先驗地存在。

+1

更新 應根據註釋創建表。在非Spring應用程序中,當我配置所有在hibernate.cfg.xml中它工作,但現在我有問題。 –

+0

我知道它應該做什麼;不要這樣做。 – duffymo

-1

在情況下,如果你已經正確執行了所有的手續,但仍然得到錯誤,請檢查「hibernate.dialect」是否被設置爲MySQL5Dialect如果你使用MySQL作爲數據庫。