[EJB 3.0] - Error Injecting EntityManager
by liss_jboss
Hi guys,
I hava an EJB project and I separated it into two components: service.jar (which contains only interfaces) and service-impl.jar (which contains implementation of those interfaces).
At service.jar I've a ordinary interface. At service-impl.jar I've an local interface (@Local), remote interface (@Remote) and a bean (@Stateless).
All those compoments are packaged into a ear file.
The problem is that in one of my stateless, when injecting an EntityManager object, the following error occurs:
| # Caused by: java.lang.RuntimeException: Non matching type for inject of field: private javax.persistence.EntityManager br.unicamp.hc.caa.ejb.eao.PeriodoCadastralEAOBean.entityManager for type: org.jboss.ejb3.entity.InjectedEntityManagerFactory of jndiName env/br.unicamp.hc.caa.ejb.eao.PeriodoCadastralEAOBean/entityManager
| # intfs: , javax.persistence.EntityManagerFactory, java.io.Externalizable
| # at org.jboss.injection.JndiFieldInjector.inject(JndiFieldInjector.java:127)
| # at org.jboss.injection.JndiFieldInjector.inject(JndiFieldInjector.java:105)
| # at org.jboss.injection.JndiFieldInjector.inject(JndiFieldInjector.java:62)
| # at org.jboss.ejb3.AbstractPool.create(AbstractPool.java:111)
| # at org.jboss.ejb3.ThreadlocalPool.get(ThreadlocalPool.java:61)
| # at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:54)
| # at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| # at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
| # at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:106)
| # at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| # at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
| # at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| # at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
| # at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| # at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:214)
| # at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:184)
| # at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:81)
| # at $Proxy124.findUltimoPeriodoCadastral(Unknown Source)
| # at br.unicamp.hc.caa.ejb.facade.PeriodoCadastralFacadeBean.findUltimoPeriodoCadastral(Unknown Source)
| # at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| # at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
| # 09:56:32,011 ERROR [STDERR] 39)
| # at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| # at java.lang.reflect.Method.invoke(Method.java:597)
| # at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
| # at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
| # at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
| # at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| # at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
| # at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| # at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
| # Caused by: java.lang.IllegalArgumentException: Can not set javax.persistence.EntityManager field br.unicamp.hc.caa.ejb.eao.PeriodoCadastralEAOBean.entityManager to org.jboss.ejb3.entity.InjectedEntityManagerFactory
|
This error occurs only when I call stateless session bean. Deployment is fine.
Does anybody know what's going on?
Thanks in advance
LISS
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4099223#4099223
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4099223
18Â years, 6Â months
[JBoss Seam] - Re: Destroying Context Variable
by jamesjmp
hello again,
Terry, Pete and whoever.., this is the problem I´m facing:
I´ve created an app by means of seam-gen without EJB3 (seam version is 1.2.1)
Let´s call the table RstReport, the following steps work fine:
- creating new data (RstReportEdit.xhtml and RstReportEdit.page)
- details of a new RstReport displayed in the RstReport.xhtml
- list of records in RstReportList.xhtml.
This are my issues:
- after creating a new RstReport, let´s call it RstReport3, if just after that I want to create a new one, the
RstReportEdit.xhtml shows the fields the RstReport3 that I´ve just created. I must log out and log in again and then the RstReportEdit.xhtml displays no previous data.
- If I go to the list, and select one row, for instance RstReport3 row to display its data (view.gif that goes to RstReport.xhtml). After having a look to that previously created RstReport, I go to create a new one, again the RstReportEdit.xhtml displays the RstReport3 data. Whenever I change one field in that edit window, RstReport 3 data is updated right away in the database.
What happens is logic, because all this pages work with the same RstReportHome object, and the RstReport of the instance hasn´t been cleaned. What should be the best way to avoid logging out each time to clean the session? (seam 1.2.1) This is what I´ve tried up to now:
- I´ve overriden persist method in the RstReportHome this way: (rstReportHome is the name of my component)
| @Override
| public String persist() {
| log.info("Home - persist");
| String returnStatus = super.persist();
| Contexts.removeFromAllContexts("rstReportHome");
| return returnStatus;
| }
|
| @Override
| public String remove() {
| log.info("Home - remove");
| String returnStatus = super.remove();
| Contexts.removeFromAllContexts("rstReportHome");
| return returnStatus;
| }
|
| @Override
| public String update() {
| log.info("Home - update");
| String returnStatus = super.update();
| Contexts.removeFromAllContexts("rstReportHome");
| return returnStatus;
| }
|
With that after creating a new RstReport, if I go again to the edit view, all works fine. But the problem keeps on happening if I go through RstReportList.xhtml --> RstReport.xhtml -->RstReportEdit.xhtml (it shows same data, RstReport3, displayed in RstReport.xhtml)
I go to RstReportEdit.xhtml by means of a rich:menuItem
| <rich:menuItem value="#{messages['New']}" action="/RstReportEdit.xhtml"/>
|
To prevent that data from being displayed I´ve added in the invocation this:
| <rich:menuItem value="#{messages['New']} param NewReport" action="/RstReportEdit.xhtml?action=NewReport">
| </rich:menuItem>
|
Then in the wire I check that param, and in that case I do this:
| public void wire() {
| try {
| if (action.equals("NewReport")) {
| clean();
| }
| ..
| }
|
| public void clean() {
| log.info("limpiando instancia...");
| Contexts.removeFromAllContexts("rstReportHome");
| this.setInstance(createInstance());
|
| }
| @Override
| protected RstReport createInstance() {
| log.info("createInstance...............");
| RstReport rstReport = new RstReport();
|
| Date dat = new Date();
| rstReport.setReportDate(dat);
|
| Firm firma = new Firm();
| rstReport.setFirm(firma);
| firmHome.setInstance(firma);
|
| CfgBenchmark benchmark = new CfgBenchmark();
| rstReport.setCfgBenchmark(benchmark);
| cfgBenchmarkHome.setInstance(benchmark);
|
| CfgCurrency currency = new CfgCurrency();
| cfgCurrencyHome.setInstance(currency);
| rstReport.setCfgCurrency(currency);
|
| Fund cartera = new Fund();
| fundHome.setInstance(cartera);
| rstReport.setFund(cartera);
|
| //default values
| rstReport.setConfidenceLevel(0.99);
|
| short timeHorizonDefault = 5;
| rstReport.setTimeHorizon(timeHorizonDefault);
|
| rstReport.setShortDescription(" ");
|
| byte codeIni = 0;
| RstStatus rstStatus = new RstStatus();
| rstStatus.setCode(codeIni);
| rstStatus.setDescription("NOT READY");
| rstReport.setRstStatus(rstStatus);
| log.info("RstReportHome createdInstance!!");
| return rstReport;
| }
|
And to prevent data from being updated whenever changed I´ve added bypassUpdates="true" in all fields this way:
| <a:support bypassUpdates="true" event="onblur" reRender="confidenceLevelDecoration"/>
|
Pete, is this the proper way to achieve this with seam 1.2.1? (Terry I haven´t check your invocation option up to now)
I could provide you with more code if you would like to.
thanks in advance!
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4099219#4099219
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4099219
18Â years, 6Â months