I've got an issue with a CMP EJB I've written. It deploys OK on Weblogic 7.0, and the remote interface works as expected. If I try and create a local home interface, I dont seem to get an exception, and the code (a STRUTS action) seemingly executes OK.
This is my first CMP bean, and it also has relationships, so I'm sure I'm doing something wrong somewhere!
My client code is as follows:
Properties namingServiceProperties = new Properties ();
Context ctx = new InitialContext(namingServiceProperties);
// get the local home interface
ContentLocalHome contentLocalHome = ctx.lookup("ContentLocalHome");
// the code doesn't seem to run the next few statements, and I can't see any exceptions thrown.
System.out.println("testing if we have our interface");
contentBean = contentHome.findByContentID(strId);
If I lookup "ContentHome" it does execute the next bits of code, I get a ClassCastException as you would expect, as it's returning the container implementation of the home interface.
The JNDI names are set to the shown values in the weblogic-ejb-jar.xml file, and if I use any other values, I get a finder exception, so I dont think that's the problem...
very confused, any help would be great!
Sorry, this line does read:
ContentLocalHome contentHome = (ContentLocalHome)ctx.lookup("ContentLocalHome");
Since you are using "new InitialContext(namingServiceProperties)" get the initial context, I am assuming this client is not a EJB/Servlet in the WL server instance. So, I am curious how come you are using local home interface?
this is a common mistake, a lot of people don't realise that you can default the context stuff and just do
Context ctx = new InitialContext();
As for your problem, it's difficult to see what the problem is without seeing the DD's and the full method
Being used to working entirely with remote interfaces and BMP, I'm still feeling my way around here... I do understand the notion of default context in this situation.
I've assumed that 'running in the same JVM' is having an EJB deployed and having the Struts controller servlet running on the same server, in the same application, thus Local Interfaces could be used. I could be quite wrong here!
The other reason I've used local interfaces here, is that when builing my CMP ejb with weblogic.ejbc, it dictated that the CMR field is to return the local implementation of the bean, if the bean has local interfaces, which I'm hoping it will.
This has confounded me somewhat, as you obviously cannot expose the local interfaces in the remote bean, thus the two signatures of this method are incompatible. I've had to comment out the remote bean CMR field getter and setter to get this bean to build with weblogic.ejbc. This just doesn't seem right to me, as it means that the EJB Object remote interface will be incomplete.
/*public Template getTemplate() throws RemoteException;
public void setTemplate(Template template) throws RemoteException; */
public TemplateLocal getTemplate();
public void setTemplate(TemplateLocal template);
Thanks for all the useful replies. Anymore feedback welcome!!
After a lot of reading and playing around, I've now got my head around the method signature issue for the local and remote interfaces, and the restrictions of the local interfaces there. No huge dramas there, but I still need to resolve these two questions:
- Does Struts run in the same JVM as the EJBs? I think my definition of what constitutes 'the same JVM' is unclear. In my case, Weblogic is running in 'development mode' with an exploded directory. The EJBs are in separate jar files, and my struts action classes are deployed to an exploded directory. Could this be the problem? Would bundling the package into an .ear or similar fix the local interface lookup problem?
- also, is it a bad thing to use CMR with purely remote interfaces? This seemingly works fine for me in this case.
If your client is not a web application component that assembled with you EJB in tha same EAR file or a EJB, that cannot access the local interface. In other words, a local client is a client that is collocated in the same JVM with the Enterprise JavaBean that provides the local client view. Please see EJB specification 2.0 and 2.1 for some details.
i think you can't access a local bean from a struts Action directly.<br>
what you have to do create a Remote session bean and write a method for the session bean which look ups for the local Entity bean .<br>
and you look up for the remote bean and just call the method.<br>
but make sure that your EJB's are in the same EARor jar.<br>
I'm gonna answer my own questions here.
- I bundled the whole thing into the one .ear and it works fine
- using remote interfaces for CMR is a bad thing
I'm now debating on whether to implement a session facade, or whether to continue on this way. hmm...
I am also trying to access(locally) CMP Entity bean via simple java application. But java client is not able to get the local interface. What I understood that Client is running on differnet JVM and our jar(entity beans) is using other jvm. Is it correct. I am using weblogic7.0 with Eclipse IDE.
Please answer at adityamishraa at rediffmail dot com.