巴巴运动网开发学习小记 (11-15)
1.jpa的环境配置
a.导入jpa所用的jar包,根据jpa的实现框架不同,其jar包也不同
b.新建如下配置文件src/META-INF/persistence.xml的配置文件
1 <?xml version="1.0" encoding="UTF-8"?>
2 <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
3 <persistence-unit name="cnblogs" transaction-type="RESOURCE_LOCAL">
4 <provider>org.hibernate.ejb.HibernatePersistence</provider>
5 <properties>
6 <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
7 <property name="hibernate.connection.driver_class" value="org.gjt.mm.mysql.Driver"/>
8 <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/babasport"/>
9 <property name="hibernate.connection.username" value="root"/>
10 <property name="hibernate.connection.password" value="root"/>
11 <property name="hibernate.max_fetch_depth" value="3"/>
12 <property name="hibernate.hbm2ddl.auto" value="update"/>
13 </properties>
14 </persistence-unit>
15 </persistence>
c.测试jpa环境(jpa的入口是Persistence类):
2.spring2.5+jpa的环境配置
a.导入spring所用jar包
b.新建src/beans.xml文件
1 <?xml version="1.0" encoding="UTF-8"?>
2 <beans xmlns="http://www.springframework.org/schema/beans"
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xmlns:tx="http://www.springframework.org/schema/tx"
5 xmlns:context="http://www.springframework.org/schema/context"
6 xsi:schemaLocation="http://www.springframework.org/schema/beans
7 http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
8 http://www.springframework.org/schema/tx
9 http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
10 http://www.springframework.org/schema/context
11 http://www.springframework.org/schema/context/spring-context-2.5.xsd">
12
13 <context:annotation-config/>
14 <context:component-scan base-package="cnblogs.xiaoqiu"/>
15 <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
16 <property name="persistenceUnitName" value="cnblogs"></property>
17 <property name="loadTimeWeaver">
18 <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
19 </property>
20 </bean>
21 <bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
22 <property name="entityManagerFactory" ref="entityManagerFactory"></property>
23 </bean>
24 <tx:annotation-driven transaction-manager="txManager"/>
25 </beans>
c.测试spring环境(spring的实例化类通过ClassPathXmlApplicationContext)
d.测试spring+jpa集成环境