JPA EntityManager详解

来源:互联网 发布:淘宝热带鱼活体 编辑:程序博客网 时间:2024/06/09 02:01

1.获得EntityManager对象 

两种方式:1 @PersistenceContex注入 2 JNDI获得 


private EntityManager em;


@PersistenceContext
public void setEntityManager(EntityManager em) {
this.em = em;
}


2.配置(这是用ant)

<target name="build prepare" description="build prepare ...">
<echo message="build prepare ..."/>
<echo message="create new file path ..."/>
<mkdir dir="${outwar.dir}"/>
<mkdir dir="${outbasesrc.dir}"/>
<mkdir dir="${outwebsrc.dir}"/>
<mkdir dir="${outwar.dir}/${web}/${WebContent}/echain"/>
<mkdir dir="${outwar.dir}/${web}/${WebContent}/FusionCharts/"/>
<mkdir dir="${outlib.dir}"/> 
<echo message="copy web config files ..."/>
<copy todir="${outwebsrc.dir}" preservelastmodified="true" overwrite="true">
<fileset dir="${websrc.dir}">
<include name="applicationContext-crm.xml"/>
<include name="applicationContext-dataSource.xml"/>
<include name="applicationContext-security.xml"/>
<include name="applicationContext-ytec-crm-exception.xml"/>
<include name="applicationContext.xml"/>
<include name="bip.cer"/>
<include name="bip.properties"/>
<include name="default-domain.cfg"/>
<include name="ehcache.xml"/>
<include name="extendpoint-ytec-crm-exception.xml"/>
<include name="struts.xml"/>
<include name="systemProperties.properties"/>
<include name="META-INF/MANIFEST.MF"/>
<include name="META-INF/persistence.xml"/>
</fileset>
</copy>
</target>


META-INF配置

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="BOB_JPA_ORACLE">
<jar-file>WEB-INF/lib/crmbase.jar</jar-file>
</persistence-unit>
</persistence>

原创粉丝点击