Static methods in Session Beans problem

Can a Stateful Session Bean have a static method?
public static String foo();
I tried to add a static method to a Stateful Session bean but had two problems:
When I tried to add the static modifier to the Remote interface:
static String foo();
I got the following error message:
Error(12,17): modifier static not allowed here
When I tried to compile code calling this function :
MyClass.foo();
I got this message:
Error(795,42): non-static method getNewSuffix(java.lang.String) cannot be referenced from a static context
Even though a static method was compiled in this class. I assume it can't find the static modifier in the Remote interface which wasn't allowed. Are static methods allowed in EJB's at all?

dear friend,
1) Interfaces may not contain static functions!
2) EJBs doesnt support static methods !
Maybe you should go and learn more about Java and EJB's ?

Similar Messages

  • Static variable in session bean

    Can we declare static variable in session bean. If we declare what will happen. Will it create error in compile time or not deployed in server.

    From a Java language perspective, nothing stops you from declaring a static variable in a session
    bean class. It will compile as long as its syntactically correct.
    From an EJB programming model perspective, the use of non-final static variables
    is discouraged because it breaks the JVM-transparency that is an important aspect of the
    EJB architecture. It should be possible to deploy a single EJB application to a cluster and
    have it behave exactly as if it were deployed to only one server instance (albeit with higher
    overall throughput/performance). Using non-final static variables breaks this property
    because the bean instances in one JVM will see a different value for the static variable
    than bean instances in a different JVM.
    It also forces you to deal with synchronization
    of the shared data, which is a complexity that was carefully avoided in the EJB programming
    model by ensuring that each bean instance is single-threaded.
    Bottom line is you can have "final static" data members in EJB classes but you should
    avoid non-final (mutable) static data.
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Plz help!! idempotent methods stateful session beans? (failover)

              plz help!! idempotent methods stateful session beans? (failover)
              Hi there,
              Im trying to failover my shopping cart implemented using stateful ejb, the replication
              is working but the failover is not (Object not found exception....).
              By design is hard to think on an stateful ejb using idempotent methods, but after
              checking the documentation in detail im completely confused, so im starting to
              wonder if i should use idempotent methods or manual retry in case one server is
              down.
              Plz take a loo at these explanations about faiolver in the WLS edocs.
              "....With clustered objects, automatic failover generally occurs only in cases
              where the object is idempotent.....Because of this, replica-aware stubs will not,
              by default, attempt to retry a method that fails after the request is sent but
              before it returns. This behavior can be overridden by marking a service idempotent..."
              BUT
              "By default, a stateful session bean's Home stub provides load balancing and failover
              for its method invocations to any clustered server where the bean is deployed...."
              So is possible to achieve automatic failover (not only load balancing) for stateful
              ejb without having to worry about state-changes or manual retry. (i know the retry
              is requiered if the server crashed just before finishing a transaction but this
              is not what im talking about).
              Any help will be highly appreciated
              Alan
              

              Ryan,
              Yes, im deploying using In-memory replication and clusterable elements, when try
              to invoke the method (after one of the nodes is down) i recieve an "java.rmi.NoSuchObjectException:
              Bean has been deleted".
              I believe all this could be related to some sort of issue with JNDI Lookup in
              the cluster, but haavent been able to get a clue to make it work....(almost desesperate
              by now)
              Alan
              "ryan upton" <[email protected]> wrote:
              >Alan,
              >
              >If the state isn't maintained during failover I would suspect a
              >configuration error. Have you set the <replication-type> element within
              ><stateful-session-clustering> tag in the bean's deployment descriptor?
              >
              >"Alan" <[email protected]> wrote in message
              >news:40e17cf7$1@mktnews1...
              >>
              >> Ryan,
              >>
              >>
              >> Maybe i didnt explain myself, in the scenario im dealing with I KNOW
              >the
              >method
              >> finished succesfully (example, the user succesfully added an item to
              >a
              >cart).
              >>
              >>
              >> Just after that one of the nodes goes down, and the user decides to
              >add a
              >new
              >> item (new invocation , not a retry of failed one) on the same session.
              >>
              >> This is the case in which failover should work automatically as you
              >say,
              >meaning
              >> the new method invokation should be able to retrieve the session state
              >info from
              >> the replica and switch the primary.....Well, this is the part wich
              >isnt
              >working
              >> :( as i understand it should transparently
              >>
              >> I believe could be a config issue , but have no way to make it work.
              >>
              >> Regards,
              >>
              >> Alan
              >> "ryan upton" <[email protected]> wrote:
              >> >
              >> >"Alan" <[email protected]> wrote in message
              >news:40e06296@mktnews1...
              >> >>
              >> >> Ryan,
              >> >>
              >> >> Thanks for clearing the both conditions a bit more, in this case
              >my
              >> >issue
              >> >has
              >> >> to do with the scenario #1 in which subsequent calls (invocations)
              >> >go to a
              >> >node
              >> >> which isnt avaliable(down), do you have any idea of in what conditions
              >> >the
              >> >"automnatic"
              >> >> failover would fail??? (meaning why the stub would try to dispatch
              >> >a call
              >> >to the
              >> >> same previous node)
              >> >>
              >> >> Thanks for the help again
              >> >>
              >> >
              >> >Subsequent calls won't go to a node that's down. That's the whole
              >> >point
              >> >;-). Failover is always automatic, what you are getting confused
              >on
              >> >is
              >> >automatic method re-execution upon failover which happens if the method
              >> >has
              >> >been marked as idempotent. The logic is this: if I failover to an
              >EJB
              >> >that
              >> >I know is still alive, I can't safely call the same method again.
              > Why?
              >> >Because I don't know how much of the method completed the last time
              >before
              >> >the previous bean's failure. So if the bean can yield multiple results
              >> >from
              >> >multiple invocations I had better play it safe and not re-execute
              >the
              >> >method
              >> >on the bean I failed over to (unless it's idempotent because in that
              >> >case it
              >> >doesn't matter how many times I call it, it always does the same thing).
              >> > In
              >> >scenario #1 and #2 failover is automatic and all new calls are executed
              >> >against the bean the client failed over to, but only idempotent methods
              >> >are
              >> >re-executed.
              >> >
              >> >
              >>
              >
              >
              

  • Enterprise Session Bean Problem

    Dear Experts,
    I have just installed Netweaver Developer Studio 7.1 Composition Environment and is doing some development on it from the tutorial in the following link
    [http://help.sap.com/saphelp_nw04/helpdata/en/c3/679564e11d482f8a706b423f67e56c/content.htm|http://help.sap.com/saphelp_nw04/helpdata/en/c3/679564e11d482f8a706b423f67e56c/content.htm]
    I have created a new EJB Project using the Configuration SAP EJB J2EE 1.4 Project and created a new stateless session bean Calculator. 
    I finished creating the session bean with all the BUSINESS METHODS, but when I expand the project node Calculator in the J2EE Explorer, I CANNOT see the Calculator.java class.  All other classes such as CalculatorBean.java, CalculatorHome.java, etc are present. 
    This is where the problem comes, when I create the JavaBean in the Web Module I will need to access the Calculator.java class and now I cannot access it since it is missing.
    Can you please guide me on how to generate the Calculator.java class in the session bean.
    Points will be rewarded for correct answers.
    Thanks in advance
    Edited by: jamison2004 jordan2004 on May 7, 2008 11:16 AM
    Edited by: jamison2004 jordan2004 on May 7, 2008 11:25 AM

    Hi jamison jordan,
    Maybe you check the CE version of the documentation:
    [Creating Your First J2EE Application|http://help.sap.com/saphelp_nwce10/helpdata/en/c3/679564e11d482f8a706b423f67e56c/frameset.htm]
    kind regards
    Stefanie

  • Static methods in Session EJB

    Dear Friends,
    This is kind of urgent.I have a very simple question and I need everyone of ur's opinion on something.I was currently wokring on a web based project.The architect of the project designed to use Session and Entity beans.
    He asked me to put "Static" methods in the Session EJB to produce generated HTML pages.for example
    public ststic String getPage(myBean);
    I'd like to hear ur comments on this.
    Thanks
    Jewel

    In general, mixing HTML and business logic is not very good practice. EJBs were created in part to separate presentation and business logic (among various other reasons), and this type of design goes against that goal.
    What's wrong with using JSPs and controller/proxy JavaBeans to interface with the EJBs and create your presentation HTML?

  • Multiple session bean problem

    Hi,
    I am developing an admin module to my web app and have created a 2nd session bean to manage data within the admin component of the site just to keep things cleaner and more logical. However there is a problem which I cannot overcome.
    The source code to my main website is located in soulsurfing package. The source code to my admin website is located in soulsurfing.admin package. Inside this package is the java code to my admin web pages and a 2nd session bean called adminSessionBean. So far so good.
    I dropped a database table into my admin page which created a cachedrowset (CustomerRowSet) in my adminSessionBean and a data provider on my admin page (CustomerDataProvider). Ok things are still going well until now.
    There are two main issues i'm facing.
    1. Setting a breakpoint in my code and trying to step through the code line by line (F10) fails whenever the adminSessionBean appears in the line of code. In actuality the system just hangs until I exit debug mode in which the page finishes loading ok. If I step into the code (F11) it still works ok and if there is no breakpoint at all it loads ok too so there is something wrong with the debugger.
    2. Most importantly there is a problem with either the cachedrowset or the data provider because it simply does not return any data from the database. The sql query works fine in both MySQL and when running from creator too so no problem here. If I put a line of code in to capture the sql statement such as String test_var3 = getAdmin$adminSessionBean().getCustomerRowSet().getStatement().toString() a null exception is thrown. However if I ditch the 2nd session bean (adminSessionBean) and run everything exactly the same through the original session bean (SessionBean1) located in soulsurfing package then it all works fine so there must be conflict somewhere with having multiple session beans perhaps in different packages.
    Can anybody help me?
    Below is the java code to my web page that sets and executes the cachedrowset in the prerender method that is failing. Further below that is the code to my 2nd session bean.
    Thanks.
    customer_list.java
    package soulsurfing.admin;
    import com.sun.rave.web.ui.appbase.AbstractPageBean;
    import com.sun.rave.web.ui.component.Body;
    import com.sun.rave.web.ui.component.Form;
    import com.sun.rave.web.ui.component.Head;
    import com.sun.rave.web.ui.component.Html;
    import com.sun.rave.web.ui.component.Link;
    import com.sun.rave.web.ui.component.Page;
    import javax.faces.FacesException;
    import com.sun.rave.web.ui.component.TextField;
    import com.sun.rave.web.ui.component.Button;
    import com.sun.rave.web.ui.component.PageSeparator;
    import com.sun.rave.web.ui.component.StaticText;
    import com.sun.rave.web.ui.component.Table;
    import com.sun.rave.web.ui.component.TableRowGroup;
    import com.sun.rave.web.ui.component.TableColumn;
    import com.sun.data.provider.impl.CachedRowSetDataProvider;
    import com.sun.rave.web.ui.component.MessageGroup;
    import com.sun.rave.web.ui.model.DefaultTableDataProvider;
    public class customer_list extends AbstractPageBean {
        private int __placeholder;
        private void _init() throws Exception {
            customerDataProvider.setCachedRowSet((javax.sql.rowset.CachedRowSet)getValue("#{adminSessionBean.customerRowSet}"));
        private Page page1 = new Page();
        public Page getPage1() {
            return page1;
        public void setPage1(Page p) {
            this.page1 = p;
        private Html html1 = new Html();
        public Html getHtml1() {
            return html1;
        public void setHtml1(Html h) {
            this.html1 = h;
        private Head head1 = new Head();
        public Head getHead1() {
            return head1;
        public void setHead1(Head h) {
            this.head1 = h;
        private Link link1 = new Link();
        public Link getLink1() {
            return link1;
        public void setLink1(Link l) {
            this.link1 = l;
        private Body body1 = new Body();
        public Body getBody1() {
            return body1;
        public void setBody1(Body b) {
            this.body1 = b;
        private Form form1 = new Form();
        public Form getForm1() {
            return form1;
        public void setForm1(Form f) {
            this.form1 = f;
        private TextField textField1 = new TextField();
        public TextField getTextField1() {
            return textField1;
        public void setTextField1(TextField tf) {
            this.textField1 = tf;
        private TextField textField2 = new TextField();
        public TextField getTextField2() {
            return textField2;
        public void setTextField2(TextField tf) {
            this.textField2 = tf;
        private Button button1 = new Button();
        public Button getButton1() {
            return button1;
        public void setButton1(Button b) {
            this.button1 = b;
        private Button button2 = new Button();
        public Button getButton2() {
            return button2;
        public void setButton2(Button b) {
            this.button2 = b;
        private PageSeparator pageSeparator1 = new PageSeparator();
        public PageSeparator getPageSeparator1() {
            return pageSeparator1;
        public void setPageSeparator1(PageSeparator ps) {
            this.pageSeparator1 = ps;
        private StaticText staticText1 = new StaticText();
        public StaticText getStaticText1() {
            return staticText1;
        public void setStaticText1(StaticText st) {
            this.staticText1 = st;
        private StaticText staticText2 = new StaticText();
        public StaticText getStaticText2() {
            return staticText2;
        public void setStaticText2(StaticText st) {
            this.staticText2 = st;
        private Table table1 = new Table();
        public Table getTable1() {
            return table1;
        public void setTable1(Table t) {
            this.table1 = t;
        private TableRowGroup tableRowGroup1 = new TableRowGroup();
        public TableRowGroup getTableRowGroup1() {
            return tableRowGroup1;
        public void setTableRowGroup1(TableRowGroup trg) {
            this.tableRowGroup1 = trg;
        private MessageGroup messageGroup1 = new MessageGroup();
        public MessageGroup getMessageGroup1() {
            return messageGroup1;
        public void setMessageGroup1(MessageGroup mg) {
            this.messageGroup1 = mg;
        private CachedRowSetDataProvider customerDataProvider = new CachedRowSetDataProvider();
        public CachedRowSetDataProvider getCustomerDataProvider() {
            return customerDataProvider;
        public void setCustomerDataProvider(CachedRowSetDataProvider crsdp) {
            this.customerDataProvider = crsdp;
        private TableColumn tableColumn2 = new TableColumn();
        public TableColumn getTableColumn2() {
            return tableColumn2;
        public void setTableColumn2(TableColumn tc) {
            this.tableColumn2 = tc;
        private StaticText staticText4 = new StaticText();
        public StaticText getStaticText4() {
            return staticText4;
        public void setStaticText4(StaticText st) {
            this.staticText4 = st;
        private TableColumn tableColumn3 = new TableColumn();
        public TableColumn getTableColumn3() {
            return tableColumn3;
        public void setTableColumn3(TableColumn tc) {
            this.tableColumn3 = tc;
        private StaticText staticText5 = new StaticText();
        public StaticText getStaticText5() {
            return staticText5;
        public void setStaticText5(StaticText st) {
            this.staticText5 = st;
        private TableColumn tableColumn11 = new TableColumn();
        public TableColumn getTableColumn11() {
            return tableColumn11;
        public void setTableColumn11(TableColumn tc) {
            this.tableColumn11 = tc;
        private StaticText staticText13 = new StaticText();
        public StaticText getStaticText13() {
            return staticText13;
        public void setStaticText13(StaticText st) {
            this.staticText13 = st;
        public customer_list() {
        protected adminSessionBean getAdmin$adminSessionBean() {
            return (adminSessionBean)getBean("admin$adminSessionBean");
        protected soulsurfing.ApplicationBean1 getApplicationBean1() {
            return (soulsurfing.ApplicationBean1)getBean("ApplicationBean1");
        protected soulsurfing.SessionBean1 getSessionBean1() {
            return (soulsurfing.SessionBean1)getBean("SessionBean1");
        protected soulsurfing.RequestBean1 getRequestBean1() {
            return (soulsurfing.RequestBean1)getBean("RequestBean1");
        public void init() {
            super.init();
            try {
                _init();
            } catch (Exception e) {
                log("customer_list Initialization Failure", e);
                throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
        public void preprocess() {
        public void prerender() {
            try {
                if (getAdmin$adminSessionBean().getFilter1().equalsIgnoreCase("")) {
                    getAdmin$adminSessionBean().getCustomerRowSet().setString(1, "%");
                } else {
                    getAdmin$adminSessionBean().getCustomerRowSet().setString(1, getAdmin$adminSessionBean().getFilter1());
                if (getAdmin$adminSessionBean().getFilter1().equalsIgnoreCase("")) {
                    getAdmin$adminSessionBean().getCustomerRowSet().setString(2, "%");
                } else {
                    getAdmin$adminSessionBean().getCustomerRowSet().setString(2, getAdmin$adminSessionBean().getFilter2());
                getAdmin$adminSessionBean().getCustomerRowSet().execute();
                customerDataProvider.refresh();
                customerDataProvider.cursorFirst();
                getAdmin$adminSessionBean().setRowCount(customerDataProvider.getRowCount());
                getAdmin$adminSessionBean().setMsg(getAdmin$adminSessionBean().getRowCount() + " records returned.");
                //i have a breakpoint here which hangs when stepping over code however works if breakppoint not set
                String test_var1 = getAdmin$adminSessionBean().getFilter1();
                int test_var2 = getAdmin$adminSessionBean().getRowCount();
            } catch (Exception e) {
                log("Exception occurred!!", e);
                error("Error: "+e.getMessage()); //null exception is being caught
        public void destroy() {
            customerDataProvider.close();
    adminSessionBean.java
    package soulsurfing.admin;
    import com.sun.rave.web.ui.appbase.AbstractSessionBean;
    import javax.faces.FacesException;
    import com.sun.sql.rowset.CachedRowSetXImpl;
    public class adminSessionBean extends AbstractSessionBean {
        private int __placeholder;
        private void _init() throws Exception {
            customerRowSet.setDataSourceName("java:comp/env/jdbc/SoulSurfing_User");
            customerRowSet.setCommand("SELECT * \nFROM customer ");
            customerRowSet.setTableName("customer");
        private CachedRowSetXImpl customerRowSet = new CachedRowSetXImpl();
        public CachedRowSetXImpl getCustomerRowSet() {
            return customerRowSet;
        public void setCustomerRowSet(CachedRowSetXImpl crsxi) {
            this.customerRowSet = crsxi;
        public adminSessionBean() {
        protected soulsurfing.ApplicationBean1 getApplicationBean1() {
            return (soulsurfing.ApplicationBean1)getBean("ApplicationBean1");
        public void init() {
            super.init();
            try {
                _init();
            } catch (Exception e) {
                log("adminSessionBean Initialization Failure", e);
                throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
        public void passivate() {
        public void activate() {
        public void destroy() {
        private String filter1 = "";
        public String getFilter1() {
            return this.filter1;
        public void setFilter1(String filter1) {
            this.filter1 = filter1;
        private String filter2 = "";
        public String getFilter2() {
            return this.filter2;
        public void setFilter2(String filter2) {
            this.filter2 = filter2;
        private int rowCount;
        public int getRowCount() {
            return this.rowCount;
        public void setRowCount(int rowCount) {
            this.rowCount = rowCount;
        private String msg;
        public String getMsg() {
            return this.msg;
        public void setMsg(String msg) {
            this.msg = msg;
    }

    Hi Harini,
    What I didn't explain in my initial post is that there are more than 2 views in my application.  There are a total of 9 jsp's so far, so I coded multiple controllers due to the high amount of views.  After taking the HTMLB training class, I noticed that the examples used contained no more than 2 jsp's, so only 1 controller was needed.
    However, I talked with another Portal developer, and he suggested that it would be simpler to code the application using only 1 controller.  The problem is, I will have 1 LOOOOONG controller since there are many buttons across all of the jsp's (hence many events that will need to be handled) and many beans that need to be populated.
    Harini, thanks very much for offering to view my par file.  I think I have solved the problem on my own, but could you let me know what the design standard is for an application of this size?  Think of an online banking application that needs to handle bill payment (paying the bill, viewing past payments, etc.,).
    Would you use 1 controller for this type of application?
    Thanks very much for your help.
    -Jamie

  • Using only one method in session bean to create web service

    Hi all,
    I hhave a scenario where i am inserting and retrieving data from dict table using web service.
    For this i have created a session bean and a wrapper class.
    The session bean has two methods: insertRecords(), and viewRec().
    so while creating a web service i need to include two methods.
    I want to have only one method where i can pass a parameter as operation and if it is "I", then i can call the insert method and if it is "S" i can call view method.
    I tried doing that bt i am stuck up with the return type.
    Insert method has return type as array of wrapper class and
    view method has wrapper class as return type ...
    Is this scenario possible..??
    or is there any other way to do this???
    Plz let me knw..
    Thankls n regards,
    Ankita

    Hi Siddharth,
    Im really sorry..
    i cudnt  get u ..
    Actually these r methods:
    public DemoDicModel[] viewRecords()
    and
    public DemoDicModel insertRecords(
              String title,
              String desc,
              String status)
    and im trying this:
    public DemoDicModel[] getMethods(String operation,String title,String desc, String st)
    DemoDicModel[] demoModel =null;
    DemoDicModel model = new DemoDicModel();
    if(operation == "show")
          demoModel = viewRecords();
    if(operation == "ins")
          model = insertRecords(title,desc,st);
          model.setMsg("RECORDS GENERATED");
          demoModel=
    return demoModel;
    im stuck up with insert operation.
    can  u plz explain me in detail.
    thanks,
    ankita

  • How to call a EJB method from Session bean method

    Hi all,
    I'm new to J2EE programming. I have a simple doubt .
    I have already created a lookup method for EJB bean in Session bean .
    My question is how to call a method of an ENTITY bean (say insertRow) from SESSION bean method(Say invoke_insertRow) .
    Please provide me an example code .
    Thanks in advance.

    InitialContext ctx = new InitialContext();
         GeneralEditor editor = (GeneralEditor) ctx
                        .lookup("GeneralEditorBean/remote");
              GeneralService service = (GeneralService) ctx
                        .lookup("GeneralServiceBean/remote");
              LanMu lm = new LanMu();
              lm.setName("shdfkhsad");
              editor.add(lm);

  • JDeveloper EJB3 Session Bean Problem

    Hi Everyone,
    I am new to JDeveloper. I tried to do a EJB3 Stateless Session Bean. I want to add the AroundInvoke Function to the Bean class. At below
    @AroundInvoke
    // mark this method as a bean interceptor
    public Object checkPermission(InvocationContext ic) throws Exception {
    System.out.println("*** checkPermission interceptor invoked");
    // you can implement your own security framework using interceptors
    if (!ic.getEJBContext().getCallerPrincipal().getName().equals("oc4jadmin")) {
    throw new SecurityException("Caller: '"
    + ic.getEJBContext().getCallerPrincipal().getName()
    + "' does not have permissions for method "
    + ic.getMethod());
    return ic.proceed();
    However, the Jdeveloper 11g keep show me the error message that AroundInvoke is not found. Then I put the import javax.ejb.AroundInvoke. It still complain import javax.ejb.AroundInoke not found.
    Please help and advise.
    Thank you

    A small tip - if you go to the add a library dialog in the project properties you'll see a search box at the top - you can put a class name there and JDeveloper will show you in which library it is.

  • Add session bean problems

    i tried to add session bean sets, but when i reach the 'configure EJB methods' dialog box, i cannot proceed to click on button 'finish' because of the errors "one or more collection element types are not specified: [getAuthorizerId] ".
    how to fix it??? thanx.

    this is the getAuthorizerId methods that i have written.
    public List getAuthoId (String code)throws HibernateException{
              Session ses = null;
                   try{
                        boolean trace = logger.isTraceEnabled();
                        if(trace)
                             logger.trace("Begin to search Authorizer code " + code);                    
                        ses = ThreadLocalSession.currentSession();          
                        Query query = ses.createQuery("from Authorizer as authorizer where authorizer.authoId=?");
                        query.setString(0, code);
                        List result = query.list();
                        ses.flush();
                        if(trace)
                             logger.trace("End of searching authorizer code " + code);
                        return result;
                   } catch (HibernateException e) {
                        ctx.setRollbackOnly();
                        throw new HibernateException("Unable to search authorizer code " + code, e);
                   }finally{
                        try {
                             ThreadLocalSession.closeSession();
                        } catch (HibernateException e1) {
                             e1.printStackTrace();
    is it because jsc cannot support java.util.list??

  • Call Enterprise Bean (or Database) from private Method in Session-Bean

    Hi Everybody,
    I've a question regarding the possibility to call an dependency injected EJB in an private method of a session bean.
    Imagine the following.
    @Stateless
    public class SomeBean implements SomeLocal{
       @EJB
       private AnotherLocal anotherBean;
       /** Will be called from a web-app via delegate layer */
       @TransactionAttribute(TransactionAttribute.RequiresNew)
       public void someBusisnessMethod(){
           String something = this.getSomeThing();
           //Do more
       private String getSomeThing(){
          return anotherBean.aMethodWhichCallsTheEntityManager();
    }I've to refactor code with uses such Call-Hierachy and I want to know whether this is a correct way? Somebody told me that such stuff should not be made, and I quess he told me an explanation, why not to do such stuff, but unfortunally I've forgotten that. Do someone have a suggestion why not to do this? Could it blow the application to hell? Is there any difference to the following code (The way I would have done it)?
    @Stateless
    public class SomeBean implements SomeLocal{
       @EJB
       private AnotherLocal anotherBean;
        @Resource
        private SessionContext sessionContext;
       /** Will be called from a web-app via delegate layer */
       @TransactionAttribute(TransactionAttribute.RequiresNew)
       public void someBusisnessMethod(){
           SomeLocal self = this.sessionContext.getBusinessObject(SomeLocal.class);
           String something = self.getSomeThingBusinessMethod();
           //Do more
       @TransactionAttribute(TransactionAttribute.Required)
       public String getSomeThingBusinessMethod(){
          return anotherBean.aMethodWhichCallsTheEntityManager();
    }

    Found the answer by myself....
    Here it is if someone might have the same question:
    http://stackoverflow.com/questions/3381002 or if the link may down sometime the content of the answer...
    >
    The motivation here is that most EJB implementations work on proxies. You wouldn't be too far off in thinking of it as old-school AOP. The business interface is implemented by the EJB container, quite often via a simple java.lang.reflect.Proxy, and this object is handed to everyone in the system who asks for the ejb via @EJB or JNDI lookup.
    The proxy is hooked up to the container and all calls on it go directly to the container who will preform security checks, start/stop/suspend transactions, invoke interceptors, etc. etc. and then finally delegate the call to the bean instance -- and of course do any clean up required due to any exceptions thrown -- then finally hand the return value over through the proxy to the caller.
    Calling this.foo() directly, or passing 'this' to a caller so they can make direct calls as well, will skip all of that and the container will be effectively cut out of the picture. The 'getBusinessObject(Class)' method allows the bean instance to essentially get a proxy to itself so it can invoke its own methods and make use of the container management services associated with it -- interceptors, transaction management, security enforcement, etc.
    written by David Blevins

  • Is it usefull syncronized method in session bean?

    hi all
    I know that each time I call a session bean my appllication server create one instance.
    So i wonder if it's a wrong idea declaring each session bean methods syncronized.
    Regards

    It's generally not a good practice to call your business classes directly from javascript.
    But you can place a mediator (business delegate) java class inbetween and can access the session bean instead.
    To access any java class using ajax, you may need a remoting library like DWR or JSON-RPC.
    These libraries offer very powerful and easy way to use ajax in your application.
    But if you want a more simpler solution, then have a look at libraries like "ajax4jsf" or "ajaxanywhere".

  • Ejbpassivate and ejbactivate  methods in session beans?

    I have read in most of the sites that stateful session beans are not pooled, then when ejbpassivate and ejbactivate methods are used?
    As per my understanding ,when SFSB are pooled and all SFSB are engaged in servicing then say some request comes. Then container tries to passivate the LRU SFSB anf make it available for new request. But i think it is required in case of pooling only.
    If SFSB are not pooled is there any need of passivate/activate methods?

    It's not the SF EJB itself that is being used for multiple clients, it's the resources that are being used by the EJB that can be freed up for use by other objects while the EJB is passivated.

  • JDeveloper 10.1.3 EA 1 Session Bean Problems

    Hello,
    it seems there are some problems in JDeveloper 10.1.3 EA1 related to Session EJBs:
    1) The Create Session Bean Wizard doesn't work correctly. After finishing the Wizard, JDeveloper only creates the ejb-jar.xml and orion-ejb-jar.xml, but not the Session EJB classes/interfaces themselves (Bean, Remote, Home). So I had to develop the Session Bean in JDeveloper 10.1.3 Developer Preview. That worked fine. I finally migrated the project to 10.1.3 EA1.
    2) When I try to run my JSF/EJB application with the Session Bean in 10.1.3 EA1, the following error occurred:
    05/10/24 17:31:15 Error instantiating application 'current-workspace-app' at file: <a file path>...oc4j-app.xml:
    Error initializing ejb-modules:
    Error loading module file: <a file path>.../Model/classes/:
    Syntax error in source or compilation failed in:
    <a file path>...\Software\JDeveloper\jdevj2eebase1013\jdev\system\oracle.j2ee.10.1.3.34.12\embedded-oc4j\application-deployments\current-workspace-app\Umfragesystem02_Model_0\generated\CommandHandlerSession_StatelessSessionBeanWrapper0.java
    I have no idea how to solve this problem. Does anybody have a solution?
    Regards,
    Matthias

    Tested Session Bean and Entity Bean.<br>
    The bean class and the deployment descriptors get<br>
    generated.<br>
    The remote/local, home/local home interfaces do not<br>
    get generated.<br><br>
    Thanks. The Session Bean Creation Wizard problem is a problem I could solve using a workaround. But the problem that really stems me is the error I receive when I try to run my webapp using the Session Bean and some more classes and JavaServer Faces files:<br>
    <br>
    Error instantiating application 'current-workspace-app' at file: ...oc4j-app.xml: <br>Error initializing ejb-modules: <br>
    Error loading module file: .../Model/classes/: <br>
    Syntax error in source or compilation failed in:<br> ...\Software\JDeveloper\jdevj2eebase1013\jdev\system\oracle.j2ee.10.1.3.34.12\embedded-oc4j\application-deployments\current-workspace-app\Umfragesystem02_Model_0\generated\CommandHandlerSession_StatelessSessionBeanWrapper0.java <br>
    <br>
    What goes wrong with JDeveloper or the application?

  • Synchronized static method -is there a problem?

    Hi.
    I'm facing a problem. I have a common java class that is used by many applications. Class is in a jar file and is in server's shared library. And every applications in the server used it.
    Methods are declared static but not synchronized static. Class itself is not static. I have found that sometimes right after server is restarted and applications are using this class, method return values are mixed up or method behaviour is strange. I havent able to repeat this problem when testing with just one application.
    Is the problem static method and when using under one classloader (in shared lib) probelm occurs? So if i declare it static synchronized, does that solve my problem?

    Ok. But is it still risk to use static classes or
    static methods/fields in class that are shared with
    multiple applications ie. in servers shared library?That's a big fat YES.
    I suspect that you might benefit from investing a couple of hours in the "concurrency" tutorial
    http://java.sun.com/docs/books/tutorial/essential/concurrency/

Maybe you are looking for

  • Blue Screen error STOP:0x0000001E erro

    Hi, Have i have getting blue screen error (STOP:0x0000001E) on windows server R2 standard edition. Server is working only in safe mode with networking but not normally. Due to which server is getting rebooted again and again..please help. suhasish

  • Need help controlling external FW drives

    I have three external 800 FW drives: one WD and two G-Drives. They are each 1TB in size, and they are daisy-chained. The WD is directly connected to the MacBook Pro. The two G-Drives are chained to the WD. The G-Drive in the middle spins down with a

  • Screen Scrolls in games with arrow keys

    My kids play a lot of games online.  I can't lock the screen or whatever you want to call it.  If the game requires the arrow keys to move the character, it scrolls the screen until they can't see the game.  I have tried to click on the flash player

  • BOM Item Category (urgent)

    HI SAP Gurus, We have an issue in BOM. At first we cannot explode our BOM. The main item is in Item Category of NORM. So what we did is to change the Item Category group to ERLA. As I understand, If we use ERLA, the price will be in the Main Item and

  • Installing JDK w/ NetBeans 5.5.1 & JRE 6U1 but not working

    I downloaded and installed both of these on my Ubuntu Linux Machine. When I tried to execute the netBeans application I got: 'Make sure you have the 'multiverse' component enabled' This is a completely new IDE and Language for me, so I am just a clue