EJB+JBOOs运行test程序,EntityManager is null
来源:互联网 发布:电脑rar解压软件 编辑:程序博客网 时间:2024/06/08 09:45
EJB @PersistenceContext EntityManager Throws NullPointerException
1.junit 测试时,无法使用依赖注入的方式,得到EntityManger
@PersistenceContext(unitName = "trust")
protected EntityManager em=factory.createEntityManager();
目前JBoss 4.2集成了的Tomcat版本为5.5,但Tomcat 6.0以后的版本中才支持使用注释,所以如果将本例中Servlet运行在JBoss 4.2中,并不能获得EntityManagerFactory对象;但在符合J2EE 5.0的服务器中,这样运行是可以的。
虽然在目前JBoss 4.2版本中不支持使用注释,但可以通过另一种方式来获得应用托管的EntityManager对象
解决方案:
1.-改为通过工厂来新建
private static EntityManagerFactory factory;
static{
factory=Persistence.createEntityManagerFactory("jpaUnit");
}
protected EntityManager em=factory.createEntityManager();
外文链接:http://stackoverflow.com/questions/20592925/ejb-persistencecontext-entitymanager-throws-nullpointerexception
http://stackoverflow.com/questions/6469751/testing-an-ejb-with-junit
- EJB+JBOOs运行test程序,EntityManager is null
- Spring Data Jpa 自定义 Repository EntityManager is null
- EJB之JPA(EntityManager)
- EJB之JPA(EntityManager)
- EJB之JPA(EntityManager)
- EJB---->持久化实体管理器EntityManager
- ejb使用EntityManager调用数据库的配置
- 宁静致远_ EJB之JPA(EntityManager)
- myeclipse下配置运行EJB程序的环境
- 异常:java.lang.IllegalStateException: EntityManager is closed
- EJB中的容器托管的EntityManager持久化上下文
- EJB学习笔记十一(EntityManager几种管理方式)
- is null && is not null
- Spring Junit4 Test中JDBC事务回滚抛异常Connection is null
- What is EJB?
- What is EJB
- What is EJB
- NULL Pointer Reference Test
- Objective - C基础: 第二天 - 9.继承的使用注意
- 灰度图像--频域滤波 傅里叶变换之二维离散傅里叶变换
- IT行业的几大发展趋势
- 联想笔记本电脑连接不到无线网络的解决办法
- C# 32Bit电脑环境帮助类
- EJB+JBOOs运行test程序,EntityManager is null
- VIM 中复制和粘帖
- 考研经验交流汇
- 移动游戏又创记录!2014年为美经济创收324亿
- qtcreator在linux下的安装
- Android学习笔记之数据的内部存储方式实习数据的读写、存储到Cache实现读写
- svn安装
- A. Contest
- lombok 介绍及基本使用方法