I am learning about session beans so I wrote a simple one. I built it and deployed it to weblogic (10.3). I can see the bean under the jndi tree of the server as testsess/TestSessHome but I don't seem to be able to call the bean.
A few questions:
Why is the TestSessHome in the jndi tree? Shouldn't the remote interface that actually exposes methods I would want to use be there? Or do I have to use the home.create() to get a handle to the remote and then use it?
My client is doing something simple in the main method
Properties props = new Properties();
Context ctx = new InitialContext(props);
TestSessHome tsHome = (TestSessHome) ctx.lookup("java:comp/env/testsess/TestSessHome");
but this fails with
Exception in thread "main" javax.naming.NameNotFoundException: While trying to lookup 'java:comp.env/testsess/TestSessHome' didn't find subcontext 'java:comp'. Resolved '' [Root exception is javax.naming.NameNotFoundException: While trying to lookup 'java:comp.env/testsess/TestSessHome' didn't find subcontext 'java:comp'. Resolved '']; remaining name 'java:comp/env/testsess/TestSessHome'
Why does it have java:comp.env instead of java:comp/env? And why can't it find the java:comp subcontext?
If I try the same thing but remove the java:comp/env part I get
Exception in thread "main" java.rmi.RemoteException: Error during setSessionContext; nested exception is:
java.lang.RuntimeException: [EJB:010183]javax.ejb.EJBContext.getEnvironment is deprecated in EJB 1.1. EJB 1.1 compliant containers are not required to implement this method. Use java:comp/env instead.
I guess this is some older deprecated way of calling the EJB?
My weblogic-ejb.xml just has some basic stuff
posted 11 years ago
The answer to this is in the first case you need to use the global JNDI name as exported in your container xml config (or mappedName in EJB3) and then Narrow the reference and cast it to the home interface. You can then call create() to get a reference to the bean itself. The java:comp syntax only works within the container itself.
The reason for the EJB1.1 error is that I was following an older tutorial that has the setSessionContext call the Context.getProperties() where this is not needed in EJB >= 2.0.
A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it: