cancel
Showing results for 
Search instead for 
Did you mean: 

How to rebind a bean object programmatically in EJB 3.0

Former Member
0 Kudos

hi,

There is a bean object (EJB 3.0) which i want to rebind. How can I do it through another application running under same netweaver server.

For eg,

one session bean object is bound to "java:comp/env/Converter" jndi name by one application. Here, i need to modify this object and rebind to the same jndi name. so i used as follows,

context.rebind("java:comp/env/converter", beanobj );

//'beanobj' is the modified bean (modified attribute's value)

it was bound successfully, but when i look up the bean object, i got the ClassCastException,

like "java.lang.ClassCastException : $Proxy5_1001 at ......"

can anybody help me?

regards,

Panneer.

Accepted Solutions (1)

Accepted Solutions (1)

Vlado
Advisor
Advisor
0 Kudos

Oops, you should not do that!

Binding EJB (and other) references is in the prerogatives of the EJB container. Furthermore, it's not about binding arbitrary objects, even if you had those priviliges you cannot simply modify an object and rebind it - it does not work this way. JNDI is not an object cache!

For the sake of completeness I should also say that if you need to redirect the ejb-reference ("java:comp/env/converter") to another bean (component, not instance!) - which apparently is not your goal - currently you have to edit the deployment descriptor or the corresponding @EJB annotation and redeploy the application. In a future release of CE there will be also the possibility to do this at runtime through the NWA.

HTH!

\-- Vladimir

Former Member
0 Kudos

Hi Vladimir,

Thank you for your answer.

I actually want to monitor this bean with out altering the source code. So I wanted to create a Proxy (java.lang.reflect.Proxy) for this bean and rebind to this jndi name so as to monitor this bean. As of my knowledge NW has no support for AOP, so I tried this way.

Please let me know how to proceed to achieve the task.

Regards,

Panneer

Vlado
Advisor
Advisor
0 Kudos

Can you please elaborate on this task? What exactly do you want to monitor about the bean? Maybe there's already a standard solution...

\-- Vladimir

Former Member
0 Kudos

Hi,

We would like to see when an attribute value (of that bean object) is modified and also want to get that changed value.

Please let me know what might be that standard way to monitor the bean which you were talking about. It might be helpful for us.

Regards,

Panneer Selvam

Vlado
Advisor
Advisor
0 Kudos

I was talking about existing EJB monitors but seems it's not what you need.

Well, the obvious solution would be to encapsulate the attribute with get/set methods and do whatever monitoring you want in these methods. Doesn't this help?

\-- Vladimir

ivo_simeonov
Explorer
0 Kudos

Hi Panneer,

I think you can use EJB 3.0 interceptors in order to achieve your goal. This is pretty much an AOP like technique and it has the benefit to be portable across all Java EE platforms including SAP NetWeaver 7.1

Best Regards

Ivo Simeonov

Former Member
0 Kudos

@Vladimir Pavlov

I did not understand what you are trying to convey...

Whenever an attribute of this bean is modified we want to access that latest value.... Is there any way to know, when the attribute is modified? Just with get/set we can not know, when it is modified... am i right?

We want to achieve this without modifying the existing source code of the EJB....

-


-


@ Ivo Simeonov

As of my knowledge, to use interceptors we need to modify the EJB source code, but we do not want to touch the source code....

-


-


All this has to be achieved dynamically when the application is deployed in the production.... is it possible???

-


ivo_simeonov
Explorer
0 Kudos

Hi Panneer,

I think Vladimir's point is that having a setter/getter pair for each attribute means that all changes to the attributes will be performed via these methods hence you'll know that an invocation to a setter means a change to an attribute and vice versa. Then you'll just have to put "your"code in these getters and setters.

You can always describe the interceptors in the ejb-jar.xml which is definetely not a java source file. By the way this is the only way to attach a jar level interceptors.

- Ivo

Former Member
0 Kudos

Hi Ivo,

If you remember I told we have a need to achieve this without touching the source file. What you are again suggesting is to put my logic in the set/get methods which does not make any sense for my requirement. And also I don't want to touch the EAR file. For adding interceptors I need to modify the ejb-jar.xml present within the EAR file. Please let me know if there is any mechanism to achieve this without touching the application.

Note: I want to monitor these attributes and want to know when an attribute is modified dynamically. The application is running under production machine and we can not touch the production machine.

Regards,

Panneer Selvam

Answers (0)