Spring 实体管理器不持久
我在应用程序中遇到entitymanager问题。它不会将对象持久化到数据库 ../java/resources/META-INF/persistence.xmlSpring 实体管理器不持久,spring,entitymanager,Spring,Entitymanager,我在应用程序中遇到entitymanager问题。它不会将对象持久化到数据库 ../java/resources/META-INF/persistence.xml <persistence-unit name="dataSource" transaction-type="RESOURCE_LOCAL"> </persistence-unit> ../java/resources/database/DataSource.xml <bean class=
<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>
classpath:properties/database.properties
../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>
有什么问题吗?我认为您需要指定什么是持久性单元提供程序。例如:
<persistence-unit name="dataSource" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
</persistence-unit>
org.hibernate.ejb.HibernatePersistence
您还需要对其进行配置(例如,如果是Hibernate,使用什么方言、字符集等),并添加所有必需的依赖项
考虑使用SpringRoo工具为您简化所有这些任务如何在不使用ejb的情况下完成这些任务?以上只是指定您正在使用的JPA提供程序。不一定使用EJB(我假设您正在想象EJB2)。我认为JPA和新的EJB3是相关的。给定的代码是否在事务下运行?代码正在运行,没有异常,但不会持久化