一直在整合spring+hibernate今天整合一下JPA +Spring
persistencexml 默认放在 METAINF 目录下
Xml代码
<persistence xmlns= xmlns:xsi=instance
xsi:schemaLocation= persistence__xsd version=>
<persistenceunit name=java transactiontype=RESOURCE_LOCAL>
<provider>orghibernateejbHibernatePersistence</provider>
<class>MyClass</class>
<properties>
<property name=hibernatecacheprovider_class value=orghibernatecacheEhCacheProvider />
<property name=show_sql value=true />
<property name=hibernatecacheuse_second_level_cache value=true />
<property name=hibernatecacheuse_query_cache value=false />
</properties>
</persistenceunit>
</persistence>
view plaincopy to clipboardprint?
<persistence xmlns= xmlns:xsi=instance
xsi:schemaLocation= persistence__xsd version=>
<persistenceunit name=java transactiontype=RESOURCE_LOCAL>
<provider>orghibernateejbHibernatePersistence</provider>
<class>MyClass</class>
<properties>
<property name=hibernatecacheprovider_class value=orghibernatecacheEhCacheProvider />
<property name=show_sql value=true />
<property name=hibernatecacheuse_second_level_cache value=true />
<property name=hibernatecacheuse_query_cache value=false />
</properties>
</persistenceunit>
</persistence>
<persistence xmlns= xmlns:xsi=instance
xsi:schemaLocation= persistence__xsd version=>
<persistenceunit name=java transactiontype=RESOURCE_LOCAL>
<provider>orghibernateejbHibernatePersistence</provider>
<class>MyClass</class>
<properties>
<property name=hibernatecacheprovider_class value=orghibernatecacheEhCacheProvider />
<property name=show_sql value=true />
<property name=hibernatecacheuse_second_level_cache value=true />
<property name=hibernatecacheuse_query_cache value=false />
</properties>
</persistenceunit>
</persistence>
applicationContextxml
Xml代码
<?xml version= encoding=UTF?>
<beans xmlns= xmlns:xsi=instance
xmlns:aop= xmlns:tx=
xsi:schemaLocation= beansxsd
aopxsd
txxsd>
<bean class=orgspringframeworkormjpasupportPersistenceAnnotationBeanPostProcessor />
<bean id=Myervice class=MyService />
<bean id=dataSource class=monsdbcpBasicDataSource>
<property name=driverClassName>
<value>commysqljdbcDriver</value>
</property>
<property name=url>
<value>jdbc:mysql://localhost:</value>
</property>
<property name=username>
<value>########</value>
</property>
<property name=password>
<value>########</value>
</property>
</bean>
<! JPA EntityManagerFactoryBean for EntityManager>
<bean id=entityManagerFactory class=orgspringframeworkormjpaLocalContainerEntityManagerFactoryBean>
<property name=persistenceXmlLocation value=persistencexml />
<property name=persistenceUnitName value=java />
<property name=dataSource ref=dataSource />
</bean>
<! Transaction manager for JPA >
<bean id=transactionManager class=orgspringframeworkormjpaJpaTransactionManager>
<property name=entityManagerFactory>
<ref bean=entityManagerFactory />
</property>
</bean>
<tx:annotationdriven transactionmanager=transactionManager />
</beans>