3

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

I try difrenf configurations but nothings worked.

Any ideas what can be wrong?

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

2
  • Have you tried <prop key="hibernate.hbm2ddl.auto" value="update" /> Commented Feb 13, 2014 at 12:35
  • @KevinBowersox wrong syntax, I can't use that Commented Feb 13, 2014 at 12:39

3 Answers 3

6

use

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

As per the documentation, update updates the existing schema.

link for reference.

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
Sign up to request clarification or add additional context in comments.

Comments

1

Create the project once before you start the project and move on. Most applications assume the schema exists a priori when they start.

2 Comments

<prop key="hibernate.hbm2ddl.auto">update</prop> should create table based on annotations. In non spring app when i configure all in hibernate.cfg.xml it worked but now I have problems.
I know what it should do; don't do it.
0

In case if you have followed all the procedures correctly, but still getting the error, check whether the "hibernate.dialect" is set to MySQL5Dialect in case you use the MySQL as the database.

1 Comment

thanks it's worked i don't know how mark this answer as not useful

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.