我的应用程序中有entitymanager的问题。它不会将对象持久保存到DB ../的java /资源/ META-INF / persistence.xml中
<persistence-unit name="dataSource" transaction-type="RESOURCE_LOCAL">
</persistence-unit>
../的java /资源/数据库/ 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 / web应用/ 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>
它出了什么问题?
答案 0 :(得分:0)
我认为您需要指定什么是持久性单元提供程序。例如:
<persistence-unit name="dataSource" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
</persistence-unit>
您还需要配置它(例如,如果是Hibernate,方言,charset等)并添加所有必需的依赖项。
考虑使用Spring Roo工具为您简化所有这些任务