0

I have the following spring configuration:

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
          destroy-method="close">
        <property name="driverClassName" value="org.postgresql.Driver" />
        <property name="url" value="jdbc:postgresql://localhost/marc_test" />
        <property name="username" value="marc" />
        <property name="password" value="marc" />

    </bean>

<!-- Hibernate 3 Annotation SessionFactory Bean definition-->
    <bean id="hibernate3AnnotatedSessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="annotatedClasses">
            <list>
                <value>com.journaldev.model.Person</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.current_session_context_class">thread</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.default_schema">public</prop>
                <prop key="hbm2ddl.auto">create-drop</prop>

            </props>
        </property>
    </bean>

    <bean id="personDAO" class="com.journaldev.dao.PersonDAOImpl">
        <property name="sessionFactory" ref="hibernate3AnnotatedSessionFactory" />
    </bean>

main method:

public static void main(String[] args) {

        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");

        PersonDAO personDAO = context.getBean(PersonDAO.class);

        Person person = new Person();
        person.setName("Pankaj"); person.setCountry("India");

        personDAO.save(person);

        System.out.println("Person::"+person);

        List<Person> list = personDAO.list();

        for(Person p : list){
            System.out.println("Person List::"+p);
        }

        context.close();

    }

When does application runs I see the following error:

...    
Caused by: org.postgresql.util.PSQLException: ERROR: relation "public.person" doesn't exist

looks like hbm2ddl.auto from configuration doesn't read.
what do I wrong?

gstackoverflow
  • 34,819
  • 98
  • 304
  • 641
  • 1
    Same issue as http://stackoverflow.com/questions/10661878/why-is-hibernate-throwing-a-sqlgrammarexception-saying-table-view-does-not-exist - should be hibernate.hbm2ddl.auto as the property key? – Mark May 20 '15 at 22:05
  • @Mark thanks for your help – gstackoverflow May 21 '15 at 07:38

0 Answers0