Announcement Announcement Module
Collapse
No announcement yet.
How to use AbstractStatelessSessionBean with EJB 2.1 ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to use AbstractStatelessSessionBean with EJB 2.1 ?

    Greetings,

    I'm using WebSphere 6.1 and Spring 2.5. I have the following class:

    public class FacadeEjb extends AbstractStatelessSessionBean
    {
    //@Override
    protected void onEjbCreate() throws CreateException
    {
    //do something
    }
    }


    The wireing file looks like this:

    <jee:local-slsb id="facade" jndi-name="facade" business-interface="...FacadeEjb"/>

    A servlet is doing on its doGet method:

    BeanFactory factory = new XmlBeanFactory (new ClassPathResource ("beans.xml");
    FacadeEjb facade = (FacadeEjb)factory.getBean ("facade");


    After having deployed the whole stuff on WebSphere 6.1, I got the following exception on the servlet GET:

    Error creating bean with name 'facade'. Invocation of init method failed. Nested: javax.naming.NameNotFoundException

    The exception is raised in AbstractAutowirecapableBeanFactory.initializeBean.

    I understand that I have to define some how the bean JNDI name but I don't know how, as I dont' have any more deloyment descriptors, since my bean it's a POJO inheriting from AbstractStatelessSessionBean.

    Many thnks in adavance for any help.

    Kind regards,

    Nicolas

  • #2
    Before zooming in on your issue, you have 2 major problems

    1. Never instantiate a new BeanFactory for each request
    2. Instead of a BeanFactory you really want to use a ClassPathXmlApplicationContext.

    All the above is something you want to initialize in the init method of your servlet. You want to instantiate an ApplicationContext only once and initialize your servlet with it. Then in your doGet method simply use the retrieved object.

    Code:
    private YourBusinessInterface service;
    
    public void init() {
      ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
      service = (YourBusinessInterface) context.getBean("facade")
    }
    
    protected void doGet(request, respone) {
      service.doSomething();
    }
    Also you want to cast to the business interface you specified not your EJB!.

    Regarding your issue, what is the jndi name of your bean? The jndi name is the name used to retrieve the EJB from the jndi context. The name is normally configured in your deployment desciptor and probaby it isn't 'facade'.
    Last edited by Marten Deinum; Mar 25th, 2008, 01:38 PM.

    Comment


    • #3
      Before zooming in on your issue, you have 2 major problems

      1. Never instantiate a new BeanFactory for each request
      2. Instead of a BeanFactory you really want to use a ClassPathXmlApplicationContext.
      Thnak you, but as you're saying, this isn't related to my question.
      Regarding your issue, what is the jndi name of your bean? The jndi name is the name used to retrieve the EJB from the jndi context.
      Thnak you for explaining what a JNDI name is but, once again, this is not related to my question.
      The name is normally configured in your deployment desciptor and probaby it isn't 'facade'.
      Yes, normally, but this is not the normal situation since I'm not developing directly a stateless session bean, but a POJO which becomes a stateless session bean by inheriting from AbstractStatelessSessionBean. At least this is my understanding. So, two possibilities:
      • Either my class Facade is a POJO and, as such, it doesnt have any deployment descriptors because it inherits the AbstractStatelessSessionBean ones.
        Or my class facade is a stateless bean, it has its own deployment descriptors, I have to deal with hermetical xml and xmi files and, in this case, I don't see much interest to extend AbstractStatelessSessionBean.
      Does anybody have a real, working sample of how to use AbstractStatelessSessionBean, not just code exceprts ?

      Many thanks in advance.

      Nicolas

      Comment


      • #4
        Your understanding of what AbstractStatelessSessionBean does/is is completly wrong! It is merely a convenience class which implements all the required methods for you nothing more nothing less. It isn't going to do anything for you!!!

        Also it makes it easier to use Spring to dependency inject stuff INTO your EJB it has callback methods! I strongly suggest you readup on what a Stateless Session Bean is and how Spring helps you with extending AbstractStatelessSessionBean. Chapter 18.2 is what you want to read.

        Comment


        • #5
          Sorry to have to re-iterate my question but ... it was: does any body have a real/working sample of using AbstractStatelessSessionBean ? I mean, an EAR that I can deploy and run ? This is what I'd be interested into.

          Many thanks in advance,

          Nicolas

          Comment


          • #6
            Originally posted by nicolasduminil View Post
            Sorry to have to re-iterate my question but ... it was: does any body have a real/working sample of using AbstractStatelessSessionBean ? I mean, an EAR that I can deploy and run ? This is what I'd be interested into.

            Many thanks in advance,

            Nicolas
            If you really, really need websphere deployable EAR i have simple application i can tune and send you...

            But Martin presented you step by step instruction so just a little bit effort and reading from your side and i am sure you can do it on your own

            Comment


            • #7
              Originally posted by nicolasduminil View Post
              Yes, normally, but this is not the normal situation since I'm not developing directly a stateless session bean, but a POJO which becomes a stateless session bean by inheriting from AbstractStatelessSessionBean. At least this is my understanding.
              I think you may have misunderstood.

              If you subclass from AbstractStatelessSessionBean, then you are developing an SLSB. It is not a POJO by the very fact that it inherits from a particular base class that conforms to a particular interface or contract (that of an EJB 2.1 SLSB with methods such as ejbCreate(), etc.). A POJO would be a plain Java object with no restrictions or requirements as to superclass, interfaces or methods.

              So, two possibilities:
              Either my class Facade is a POJO and, as such, it doesnt have any deployment descriptors because it inherits the AbstractStatelessSessionBean ones.
              Your class "Facade" is a StatelessSessionBean. As an EJB 2.1 SLSB, it needs a deployment descriptor before it can be deployed, then used by client code (the servlet), properly.
              Or my class facade is a stateless bean, it has its own deployment descriptors, I have to deal with hermetical xml and xmi files and, in this case, I don't see much interest to extend AbstractStatelessSessionBean.
              Or, you might be interested in EJB 3.0 where you where you use annotations, not XML to describe your EJBs which can be real POJOs.

              Comment


              • #8
                Originally posted by miluch View Post
                If you really, really need websphere deployable EAR i have simple application i can tune and send you...

                But Martin presented you step by step instruction so just a little bit effort and reading from your side and i am sure you can do it on your own
                Many thanks. It apears that the problem I've been describing was a known bug of 2.5.1 registred in Jira. So, I didn't need step by step instructions as I was aware by them, the only thing I needed was a working example with 2.5.1 and WebSphere. Or such an example didn't exist since it only may work starting with 2.5.2. Conclusion: before giving "step by step instructions", one should check if these instructions really work. As a matter of fact, this is not because the documentation says they work that they really do.

                Comment


                • #9
                  Originally posted by alistair View Post
                  I think you may have misunderstood.

                  Or, you might be interested in EJB 3.0 where you where you use annotations, not XML to describe your EJBs which can be real POJOs.
                  This is the problem with experts: sometimes following their advice makes you do a lot of additional work. Did you notice that I'm using WebSphere ? If you did, you know that it doesn't support EJB 3.

                  Comment


                  • #10
                    Originally posted by nicolasduminil View Post
                    This is the problem with experts: sometimes following their advice makes you do a lot of additional work. Did you notice that I'm using WebSphere ? If you did, you know that it doesn't support EJB 3.
                    Websphere with some additional patches supports EJB 3.0.
                    Do not blame people who wanted to help you, blame yourself first

                    Comment


                    • #11
                      Originally posted by miluch View Post
                      Websphere with some additional patches supports EJB 3.0.
                      Of course, and the production department will patch all their servers in order to give me the opportunity to follow your advice ! Fortunatelly they won't, but just try to imagine for a second what could happen if they do !

                      Originally posted by miluch View Post
                      Do not blame people who wanted to help you, blame yourself first
                      I'm not blaming anybody and, certainly, not myself. I know you want to help but wanting is not enough. So, many thanks for your help but now, if you could stop helping me, it would help me.

                      Comment


                      • #12
                        Originally posted by nicolasduminil View Post
                        This is the problem with experts: sometimes following their advice makes you do a lot of additional work. Did you notice that I'm using WebSphere ? If you did, you know that it doesn't support EJB 3.
                        Then you can't write POJOs and expect them to act as EJBs. Simple as that.

                        Please, don't diss people who are trying to help you. Please read up on what POJO means, and how EJB 2.x works - so you'll know that you need a deployment descriptor where you have to specify your local/remote and home interfaces properly, and get your JNDI naming right, etc.

                        But, no. As you say, all the above aren't related to your problem.

                        PEBKAC.

                        Comment


                        • #13
                          My last message has disapeared as by miracle from this forum. I understand that this forum is not a democratic one and people administrating it delete messages as soon as they don't like them. If it looks like an old Soviet Union method or as a contemporary Republic of China's one, well it is.

                          I'm conscient that this message will also be deleted but I need to recapitulate the whole story. So, I didn't have enough information concerning this Spring class and I posted a question to this forum. I received immediatelly a solution saying that it was a known issue in the current version of Spring, fixed by the most recent update. The issue was closed then.

                          But strangelly enough, I continued to receive replies not really related to my question, from guys trying to teach me EJB, JNDI, etc. I have to say that, as a J2EE specialist with 9 years of exeprience (yes, since 1999 !) I don't need to be taught EJB. The only thing I needed was a sample proving a Spring specific test case, as the concerned class didn't work as stated by the documentation. Once I upgraded to the most recent patch, every thing worked normally.

                          But I'd like to say to all these persons who are poluating with non-sense replies people who had the naivity to ask a question: I don't know if, you guys, are paid to do that and more you're answering to questions, more you get paid, or if you're simply doing that in order to be able to put it on your cv. All I know is that you remember me these scenes in movies when someone is "helping" a blind person to cross the street, but the blind person doesn't want to cross the street. So before helping a blind person to cross the street please:
                          • make sure the person is blind
                          • make sure the persons wants to cross the street
                          Another metaphore: if someone stops you in the street to ask you the way, don't say: "go to the next book-shop, buy you a town map and manage yourself" because this is not at all what one's expects from you.

                          Now admin guys, you may delete this message !

                          Comment


                          • #14
                            I'd consider some anger-management therapy if I were you.

                            If you take a look at this forum you will notice that 99,9% of the people have problems with setting up basic stuff and that perhaps 0,1% leads to some interesting issues with Spring. Anyone who's wasting his own time here trying to help people for longer then a few weeks learns that people posting "How to use..." questions are trying to make stuff work without bothering to understand how it works, and your post simply looks exactly like that.

                            Comment

                            Working...
                            X