通过反射方法传递实体管理器 [英] Passing entitymanager from reflection method
问题描述
我们正在将struts2,EJB和JPA一起使用.
We are using struts2, EJB with JPA.
@PersistenceContext
private EntityManager entityManager; // Here I am getting the entitymanager
反射
Method m = c.getDeclaredMethod(methodName, params); //Here params will accept only Class<?>
现在,我想使用反射传递entitymanager
.如何在getDeclaredMethod
中传递entitymanager
?
Now I want to pass the entitymanager
using reflection. How to pass the entitymanager
in getDeclaredMethod
?
推荐答案
比利,谢谢您的答复.
现在,我们使用TransactionScopedEntityManager修复了该问题.
Now We fixed that issue using TransactionScopedEntityManager.
我们正在使用struts2 + EJB + JPA 1.0(CMT).我们有许多操作类,并且表单值将保留在DB中.最初,我们为每个动作创建了EJB.现在,我们计划为所有动作类创建一个ejb.为此,我们进行反思.
We am using struts2 + EJB + JPA 1.0 (CMT). We have many action classes and the form values will be persist in DB. Initially we created EJB for every one action. Now we are planing to one ejb for all action classes. For that we go for reflection.
使用getDeclaredMethod,我们可以传递方法名称和参数.在这里,params仅接受类.但是我们需要传递表单对象和实体管理器.我们使用了EntityManager类型,现在我们更改为TransactionScopedEntityManager.
Using getDeclaredMethod, we can pass method name and params. Here params will only accept classes. But we need to pass our form object and entitymanager. We used EntityManager type, now we changed to TransactionScopedEntityManager.
这篇关于通过反射方法传递实体管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!