2014-02-13 102 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作为数据库。