13 Replies Latest reply on Nov 13, 2008 12:24 PM by hermst

    calling transactional EJB method from another EJB component

    hermst

      In an EJB component how do you call a method from another EJB component? The method has some transactional codes.

        • 1. Re: calling transactional EJB method from another EJB component
          hermst

          I get the feeling that JBOSS SEAM is still in its infant stage judging from an almost nil response to a somewhat general problem such as this. Ok JBOSSEs can I rely on you for just a little milk of kindness to answer my simple question?

          • 2. Re: calling transactional EJB method from another EJB component
            obfuscator

            You are of course free to have an opinion, but the main reason why your question does not get answered if you ask me is that it seems trivial and not related to SEAM. I read you question as if you are simply asking how to call a method on another ejb, which I personally would not answer because it seems too trivial and I don't want to insult anyone. Maybe you imply something when you say component, but it is an unclear term that you are using. Care to elaborate?

            • 3. Re: calling transactional EJB method from another EJB component
              hermst

              Ok at last Alexander T. you're the man who can help me solve this, since this is apparently, trivial for you.


              Please backtrack a little. I posted the problem sometime ago. (23 October, repeated 27 October). Please see my whole post of
              27 October where Pawel Wrzeszcz (a JBOSS staff?) asked for source code and stack trace which I duly posted. So far he has not come back to me. Does he think this trivial like you do? Ok for the sake of triviality please provide a solution.


              Re: Calling a EJB method from another component
                   
              27. Oct 2008, 17:47
              Pawel Wrzeszcz
                   


              Please post whole stack trace and the source code.


              -Pawel

              • 4. Re: calling transactional EJB method from another EJB component
                obfuscator

                if you are referring to this, i cannot see any source code and the stack trace is incomplete (original exception is removed). Was this in another post? If not, can you paste it again here?

                • 5. Re: calling transactional EJB method from another EJB component
                  hermst
                  • 6. Re: calling transactional EJB method from another EJB component
                    obfuscator

                    Hi Jan,


                    I understand Pawels reaction not to answer, you did not provide him with the information that he needed to help you further. Of course he could have tried some other approaches, but I think the ball was in your hands at that stage.


                    The source of your problem is that the injection @In(create=true)
                    of TestComponent should work, and you need to fix this first.


                    Injections only works on class instances instantiated by JBoss (or Seam). The principle is that the container instantiates your component and sets the relevant member variables. If you instantiate with new, what you get is just a POJO with annotations, no difference to running a standalone app. This means that all instance variables will be null or what they were set to in the constructor.


                    I suspect that your injections not working is caused by some misconfiguration. I would suggest that you start with a working demo app, and modify it, instead of starting from scratch. This way you will easily see which type of mistakes you get, and can always go back to a last working configuration, plus you will have a moderately complex app to examine for examples and solutions. You will also learn to identify and diagnose common errors and their symptomes.


                    I think a lot of people on this forum has previous experience with JBoss, which really is quite complex and takes some time to get used to. It is tedious to explain all subsystems of the JBoss app server in order to explain the specifics of exceptions and errors to newcomers, wherefore I think most experienced users avoid it. Because of this syndrome, I would recommend really reading through documentation on JBoss and Seam. Understanding the concepts explained in the docs will really help you to understand the reasons to your problems.

                    • 7. Re: calling transactional EJB method from another EJB component
                      hermst

                      Ok then let's steer clear of complexities. Could you just please provide a working example of a EJB component calling a method from another EJB component using JBOSS SEAM. If you can't do it yourself you may not use the word trivial for anything not-so-trivial. And am not so sure about this. In a JIRA somewhere (I lost track of it that's why am banging my head on this trivia) this might be just the case that GAVIN KING said has no solution or implementation yet in JBOSS SEAM?

                      • 8. Re: calling transactional EJB method from another EJB component
                        wrzep

                        Hello,


                        @Alexander: Thanks.


                        @Jan:
                        Briefly:


                        This is a community forum. There is no SLA and if someone answers you it does not mean that they are assigned to the case, etc.


                        If you need fixed time responses, I can only advise you to buy a subscription. More: http://www.jboss.org/projects/community-enterprise.html


                        Furthermore, maybe you should have a look at the Forum Policy, especially at those points about bumping up your posts and attacking the community members.


                        And FYI, I do not work on Seam, I do work for JBoss and I sometimes contribute to this forum in my free time.


                        -Pawel

                        • 9. Re: calling transactional EJB method from another EJB component
                          hermst

                          Hello Pawel if someone answers me like you did asking me about something, you've engaged me into an interaction, which you should have at least (not as an obligation) but out of courtesy dealt with briefly.


                          And now you should realize this bumping, if you call it that, was an outgrowth. From day one I was as courteous and thoughtful as your POLICY would have required but you were a tease. OK?

                          • 10. Re: calling transactional EJB method from another EJB component
                            obfuscator

                            Hi Jan,


                            In your seam distribution (under the exmple folder), you will find several running example projects (circa 20). One example of a running Seam app is this website. Don't be so quick to judge. I can agree with you that the concepts are hard to grasps as a newcomer, but this doesn't mean that you are right and everyone else are wrong.


                            @Pawel: np

                            • 11. Re: calling transactional EJB method from another EJB component
                              hermst

                              Yes tnx again Alexander T. FYI I have created a complete INVENTORY APP using JBOSS SEAM guided by the examples, using annotations etc.,etc. No problem app is running fine. In my attempt to avoid duplicate codes I bumped into this problem. I could do well without EJB component calling a method from another EJB

                              • 12. Re: calling transactional EJB method from another EJB component
                                hermst
                                Hey waddaya know? Here's the answer to my problem:

                                Use the interface name not the called bean itself. So that the commented out portions of all the the following codes work when

                                @In(create=true)
                                private test_Component test_Component;

                                is changed to:

                                private TestComponent2 test_Component;

                                (TestComponent2 is the interface of test_Component bean)


                                //testAction.java
                                @Stateful
                                @Name("testComponent")
                                @Scope(ScopeType.SESSION)

                                public class testAction implements testInterface
                                {
                                  //@In(create=true) Can this work? Currently it doesn't
                                  // private test_Component test_Component;
                                       public void testMethod() {
                                      new test_Component().testrunMethod(); // a no-no? component shouldn't use new instantiation but @In doesn't work also
                                    }
                                   @Remove
                                   public void destroy() {}

                                }

                                //testInterface.java
                                @Local
                                public interface testInterface
                                {
                                    public void destroy();
                                    public void testMethod();
                                    }


                                @Stateful
                                @Name("test_Component")
                                @Scope(ScopeType.SESSION)

                                public class test_Component implements TestComponent2{
                                private List results;
                                @PersistenceContext
                                private EntityManager em;
                                @Remove
                                public void destroy() {}
                                  public boolean testrunMethod(){
                                  // results = em.createQuery("select h from Purchases h where h.prodid like 'S%'")
                                  // .getResultList();
                                    System.out.println("This works but sans code above");
                                //Even the ff doesn't work. Seems to have trouble with the EntityManager em as in above.
                                // Session sess= em.getDelegate();
                                  return true;
                                }

                                }

                                //TestComponent2.java
                                @Local
                                public interface TestComponent2
                                {
                                   public void destroy();
                                   public boolean testrunMethod();
                                }


                                Anyway thanks Alexander t. and Pawel. Bet you didn't know this? He he. Am beginning to love you guys and SEAM too which has attained teen-ager status by now. Ouch! my judgmental mouth. Gavin King you're still KING. Keep it up boy! (With all due respect.)
                                • 13. Re: calling transactional EJB method from another EJB component
                                  hermst
                                  Hey! waddya know? Backtracking I found this very encouraging castigation from Pete Muir:

                                  "I see nobody making an effort to fix the problem in that thread, just people pontificating, which gets very boring fast. On JBoss projects doers are respected, not those who make noise. So again, I invite you to do something and reduce, rather than increase, the signal to noise ratio." -- Pete Muir

                                  Good boy! I can empathize with him because although this thread is different since I asked for a simple question I didn't get any helpful answers but instead was pontificated on irrelevancies. Ciao!