0

我的应用程序中的 entitymanager 有问题。它不会将对象持久化到 DB ../java/resources/META-INF/persistence.xml

 <persistence-unit name="dataSource" transaction-type="RESOURCE_LOCAL">
    </persistence-unit>

../java/resources/database/DataSource.xml

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>classpath:properties/database.properties</value>
        </property>
    </bean>

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
    </bean>

../java/webapp/WEB-INF/applicationContext.xml

    <context:annotation-config />
    <context:component-scan base-package="com.springapp.mvc" />

    <mvc:annotation-driven/>

    <import resource="classpath:database/DataSource.xml"/>

    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="true" />
                <property name="generateDdl" value="true" />
                <property name="databasePlatform" value="org.hibernate.dialect.PostgreSQL82Dialect" />
            </bean>
        </property>

        <property name="dataSource" ref="dataSource" />
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager" />

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="dataSource" ref="dataSource" />
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>



</beans>

它有什么问题?

4

1 回答 1

0

我认为您需要指定什么是您的持久性单元提供者。例如:

<persistence-unit name="dataSource" transaction-type="RESOURCE_LOCAL">
  <provider>org.hibernate.ejb.HibernatePersistence</provider>
</persistence-unit>

您还需要配置它(例如,如果 Hibernate、什么方言、字符集等)并添加所有必需的依赖项。

考虑使用 Spring Roo 工具为您简化所有这些任务

于 2013-04-30T00:09:43.423 回答