0

我有以下弹簧配置:

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

主要方法:

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();

    }

应用程序何时运行我看到以下错误:

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

看起来hbm2ddl.auto从配置没有读取。
我错了什么?

4

0 回答 0