EJB3学习比较-JPA调用
luyued 发布于 2011-01-28 22:53 浏览 N 次1.1.1 JPA调用
1.1.1.1 J2SE
publicclass EntityManagerHelper {
privatestaticfinal EntityManagerFactory emf;
privatestaticfinal ThreadLocal
privatestaticfinal Logger logger;
static {
emf = Persistence.createEntityManagerFactory("JPA_J2SEPU");
threadLocal = new ThreadLocal
logger = Logger.getLogger("JPA_J2SEPU");
logger.setLevel(Level.ALL);
}
publicstatic EntityManager getEntityManager() {
EntityManager manager = threadLocal.get();
if (manager == null || !manager.isOpen()) {
manager = emf.createEntityManager();
threadLocal.set(manager);
}
return manager;
}
publicstaticvoid closeEntityManager() {
EntityManager em = threadLocal.get();
threadLocal.set(null);
if (em != null) em.close();
}
publicstaticvoid beginTransaction() {
getEntityManager().getTransaction().begin();
}
publicstaticvoid commit() {
getEntityManager().getTransaction().commit();
}
publicstaticvoid rollback() {
getEntityManager().getTransaction().rollback();
}
publicstatic Query createQuery(String query) {
return getEntityManager().createQuery(query);
}
publicstaticvoid log(String info, Level level, Throwable ex) {
logger.log(level, info, ex);
}
}
package com.syax.study.hibernate.jpa;
import java.util.List;
import java.util.logging.Level;
import javax.persistence.EntityManager;
import javax.persistence.Query;
- 07-01· 埃古RI&G:中国第三代休闲
- 07-01· 潇洒男士 Perry Ellis闲适生
- 07-01· 全明星阵容点亮CFDA颁奖红
- 07-01· 第十届中国休闲服装博览
- 07-01· tough jeans挎包 - 淘宝网商城
- 07-01· 钱包英语英文T开头的钱包
- 07-01· Toughjeans-散发着青春的活力
- 07-01· 平湖服装以“外”养“内
- 07-01· 护理液 海昌隐形眼镜护理
- 07-01· 潮流趋势 Red Carter 08春夏迈
- 07-01· 【中国服装面料行业投资
- 07-01· [转载]少年户外-2009中国户
- 07-01· 衡阳4s 衡阳nokia5320 nokia5
- 07-01· 挽春踏青 欢享夏风组图
- 07-01· Linux的硬链接(Hard Link)与
- 07-01· 共享精美边框和代码
- 07-01· Skyscraper Annual 航模比赛_
- 07-01· 小池一夫天涯孤客日文版
- 07-01· 绿竹与青萝
- 07-01· 四川水田惊现2亿年前生物