• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

How to Inject session bean from session bean and viceversa

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two session beans, they are StudentFacade and SchooldtFacade both of them Stateless, Remote. What I need is call StudentFacade method from SchooldtFacade and vice-versa. Below show how I did it.



If run this application using Galssfish version V2.1 ,V3 work fine without any exception. If I run it using jboss-5.1.0.GA it gave below exception.




How can I solve this problem.

Thank you.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JBoss AS has a problem with circular injection of EJBs. You can use JBoss specific @org.jboss.ejb3.annotation.IgnoreDependency on one side of the injection to get past this problem. See this thread for details https://coderanch.com/t/498867/JBoss/dependency-injection-jboss
 
dinesh thalis
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply. I'm using jboss 5.10 and netbeans 6.9.1 In here IDE can't find @IgnoreDependency , I added this also import org.jboss.annotation.IgnoreDependency; but not able to find library that contain @IgnoreDependency. please tell what is the library name should I use ?
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

dinesh thalis wrote: I added this also import org.jboss.annotation.IgnoreDependency;


That's not the correct one for AS5. The correct one for AS5 is mentioned in my previous reply. You can find that annotation in JBOSS_HOME/client/jboss-ejb3-ext-api.jar of AS5.
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you run into this problem when an EJB is referencing to itself (which is an specific case of circular injection),
you can workaround this using the SessionContext interface (SessionContext.getBusinessObject()):

EjbExampleLocal refToMyself = sessionCtx.getBusinessObject(EjbExampleLocal.class)
refToMyself.otherMethod();

Hope this helps,

Manuel
 
dinesh thalis
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is how currently my code, it works fine without any exception my application currently run on glassfish v2.1



according to your(Manuel Alberto Quero) advice change my code below show that



But it gave exception



How can I solve this issue

Thanks in advance

 
Manuel Alberto Quero
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

It seems that the problem is that you are initializing customFacade before ctx is given the proper value by the EJB container (i.e. when ctx is still null).

You can try to initialize customFacade in the method's body or if you prefer you could add a method as follows:


Just remember that this solution is valid when the EJB is referencing to itself...

Hope this can solve your problem,

Manuel
 
They worship nothing. They say it's because nothing lasts forever. Like this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic