Ejb injected in servlet

hi
I injected ejb in my servlet and I have this error in my servlet
in my if condition that I get this error:
ava.lang.ClassCastException:
swch.api.BaseEntity.Terminal cannot be cast to swch.api.BaseEntity.Terminal
public interface ITrmnlAuthenticationBL{
public Terminal find ( String serialNo, String password)
               throws GeneralException;
@Stateless
public class TrmnlAuthenticationBL implements ITrmnlAuthenticationBL{
@EJB IPersistenceManager pm;
public Terminal find ( String serialNo, String password)
               throws GeneralException {
try {
     Terminal terminal = pm.getEntityManager().createQuery("from Terminal where password = :pass and serialNo = :serial ", Terminal.class)
.setParameter("pass", password).setParameter("serial",serialNo)
.getSingleResult();
return terminal;
}catch (NoResultException e) {
          e.printStackTrace();
          return null;
catch (Exception e) {
          e.printStackTrace();
          return null;
public class EnterLet extends HttpServlet {
@EJB
private ITrmnlAuthenticationBL trmnlMg;
@Override
     protected void doPost(HttpServletRequest request, HttpServletResponse response)
               throws ServletException, IOException {
String password = request.getParameter("ps");
Terminal terminal = trmnlMg.find(serialNo, password);
****if (terminal == null || ! password.equalsIgnoreCase(terminal.getPassword()) )
I have error in this line in if condition when I used "terminal.getPassword" and can not cast Termianl from hibernate to
Terminal entity in my project...
please explain my mistake
Edited by: Marzieh on Nov 17, 2011 1:13 AM

swch.api.BaseEntity.Terminal cannot be cast to swch.api.BaseEntity.TerminalWeird huh? Java is telling you that it cannot cast an object to the exact same type.
That means that you have classloader conflicts. The same class is loaded by two different classloaders, which probably means that you have a jar with the entity deployed in two different and isolated modules (war, ear, whatever). Even if the two classes are the same, because they come from two different classloaders, to Java they are different classes and not assignable to each other.
Is all this deployed in the same EAR? If it is you shouldn't be having this problem and you must be doing something really funky in the way you deploy the stuff. If it isn't, you should deploy everything in the same ear to fix the classpath conflicts.

Similar Messages

  • @EJB injection

    Hi,
    I've seen this asked before, but there was never enough information, so I'm going to ask this again.
    I am trying a simple test with WebLogic 10.0 MP1.
    I have created an EAR file with 3 modules inside:
    1. A JAR file containing a stateless EJB.
    2. A WAR file containing a POJO webservice (using the @WebService annotation).
    3. A WAR file containing a servlet.
    The EJB code:
    public interface IHelloWorld
         public void hello();
    import javax.ejb.Local;
    import javax.ejb.Remote;
    import javax.ejb.Stateless;
    @Stateless
    @Local( IHelloWorld.class )
    @Remote( IHelloWorld.class )
    public class HelloWorld implements IHelloWorld
         public void hello()
              System.out.println( "Hello EJB3!" );
    The EJB seems to deploy fine, and I can see it in the JNDI tree, and also in the console.
    Also, I can reach the web-service and the servlet just fine.
    Now, I've added the following member to both the servlet and the web service:
         @EJB
         private IHelloWorld helloWorld;
    And in the activated method (service in the servlet, and the method on the web-service) I've added the following code:
              if ( helloWorld != null )
                   helloWorld.hello();
              else
                   System.out.println( "helloWorld is null. Bah." );
    I'm always getting that helloWorld is null, meaning the injection was not performed by the server.
    I am not using any deployment descriptors aside from application.xml in the EAR file, and the generated files in the created WAR file for the web-service (used jwsc ant to create the web-service).
    Any ideas?
    -- Nimrod

    Well, I solved it myself.
    Apparently, in order for EJB injection to work in a servlet / webservice, WebLogic server needs to know that the web application is using version 2.5 of the servlet API. To do this, replace your web-app directive in your web.xml with this:
    <web-app id="test" version="2.5"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    Now EJB injection works.

  • EJB Injection in Seperated Managed Bean

    Hi All,
    I have a JSF project consisting of a number of different WARs, containing the Web logic, and a bunch of different JARs, containing the application logic; which are deployed together in a single EAR file. Thus far this approach has worked excellently, but I've now run into a problem. I would like to have a managed session-scoped bean which should be available to all the WARs' classes so that they can store cross-application data in it (for example the user's name and other details). I can do this by packaging that session-scoped bean, along with its faces-config.xml, into a JAR which is deployed through the EAR. This works fine, but EJB Injection in that session-scoped bean doesn't work - my bean interface instance always contains null.
    Is there someway that I can have EJB Injection in this managed session-scoped bean contained in a JAR? I realize that EJB Injection requires a container, but seeing as it is a managed bean, even though it isn't inside a WAR, I thought this should work fine?
    Thank you,
    Ristretto

    We tried almost every permutation and combination, but it did not work without that dummy servlet.
    Then we had to look for a cleaner solution and we found one.
    We are now using spring injection, to get the EJB injection in our session managed bean. This way the code is extensible and cleaner.
    In future if you want something else(other than ejb lets say a web service), you will just change the Spring config file and it would't break anything.
    Edited by: desu on Mar 14, 2008 4:20 AM

  • EJB Injection into JSR286 Portlet

    I'm currently facing an issue accessing an Stateless EJB from my JSR286 Weblogic 10.3.2 Portal Server. I have 2 ears: 1) PreferencesPortalEAR and 2)PreferencesEJBEar
    PreferencesPortalEAR - contains the web module with jsr286 portlet and the ejb client jar
    PreferencesEJBEar - contains the j2ee module with the ejb and ejb client jar
    When I attempt to access the EJB from the portlet doing a JNDI lookup it works fine but when I try to use DI to get a reference to the bean I get a NullPointerException.
    Here's the code:
    PreferenceBean EJB:
    * Session Bean implementation class PreferencesBean
    @Stateless(mappedName="ejb/Preference")
    public class PreferenceBean implements PreferenceLocal, PreferenceRemote {
         @Override
         public void createPreference(List<PreferenceEntity> preferences) {
              System.out.println("Created Preference");
         @Override
         public void deletePreference(List<PreferenceEntity> preferences) {
              System.out.println("Deleted Preference");
         @Override
         public List<PreferenceEntity> getPreference(PreferenceType prefType) {
              System.out.println("Get Preference");
              ArrayList<PreferenceEntity> peAL = new ArrayList<PreferenceEntity>();
              for (int i=0;i<10;i++) {
                   PreferenceEntity pe = new PreferenceEntity();
                   pe.setId(i);
                   pe.setCreateDate(new Date());
                   pe.setPreferenceName("prefName" + i);
                   pe.setPreferenceValue("prefValue"+i);
                   pe.setUserName("weblogic"+i);
                   peAL.add(pe);
              return peAL;
         @Override
         public void updatePreference(List<PreferenceEntity> preferences) {
              System.out.println("Update Preference");
    Here's the Portlet EJBPortlet:
    public class EJBPortlet extends GenericPortlet {
         @EJB(mappedName="ejb/Preference")
         private Preference preference;
         public void doView(RenderRequest request, RenderResponse response)
                   throws PortletException, IOException {
              response.setContentType("text/html");
    //          Context ctx = null;
    //          Preference preference = null;
    //          try {
    //               /** not needed when running locally **/
    //               Hashtable<String, String> env = new Hashtable<String, String>();
    //               env.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
    //               env.put(Context.SECURITY_PRINCIPAL,"weblogic");
    //               env.put(Context.SECURITY_CREDENTIALS,"weblogic123");
    //               env.put(Context.PROVIDER_URL,"t3://localhost:7001");
    //               ctx = new InitialContext();
    //               preference = (Preference) ctx.lookup("ejb/Preference#com.mycompany.preferences.PreferenceRemote");
    //          } catch (Exception e) {
    //               e.printStackTrace();
              preference.createPreference(null);
              preference.deletePreference(null);
              ArrayList<PreferenceEntity> peAL = (ArrayList<PreferenceEntity>)preference.getPreference(PreferenceType.CATEGORY);
              for (PreferenceEntity pe : peAL) {
                   response.getWriter().write(pe.toString() + " ") ;
              response.getWriter().write("<p>Hello World!</p>");
    As previously mentioned, using InitialContext and JNDI lookup in the portlet works fine. When that code is commented and I use @EJB, I get a NullPointerException.
    Thanks for your help.

    We tried almost every permutation and combination, but it did not work without that dummy servlet.
    Then we had to look for a cleaner solution and we found one.
    We are now using spring injection, to get the EJB injection in our session managed bean. This way the code is extensible and cleaner.
    In future if you want something else(other than ejb lets say a web service), you will just change the Spring config file and it would't break anything.
    Edited by: desu on Mar 14, 2008 4:20 AM

  • 'Class Cast Exception' while invoking a EJB from a Servlet

              Hi,
              I am working on J2EE applications.I am using Webgain studio and weblogic server.I
              got a problem while invoking EJB from the servlet.
              While calling an EJB from the servlet, it is giving that "Class Cast Exception".This
              is because, the remote home reference is not able to type casted to the"Home Interface"
              of the EJB, even if I type casted explicitly. It is creating the context and able
              to identify the EJB with the JNDI name.
              Could please help me in solving this problem.I am pasting the code here.
              Thanks in advance,
              Dharma
              public void doGet(HttpServletRequest req, HttpServletResponse resp)
                   throws ServletException, IOException
                        resp.setContentType("text/html");
                        PrintWriter out = new PrintWriter(resp.getOutputStream());
              try
              Context context=getInitialContext();
              Object reference=context.lookup("ArlProjContractorAppletSession");
              ArlProjContractorAppletSessionHome home=(ArlProjContractorAppletSessionHome)PortableRemoteObject.narrow(reference,ArlProjContractorAppletSessionHome.class);
              //Exception is occuring in the above statement. It is unable
              //to cast to the home interface          
                        ArlProjContractorAppletSession the_ejb=null;
              try
              the_ejb=home.create();
              System.out.println("the_ejb = " + the_ejb.toString());
              catch(Exception e)
              e.printStackTrace();
              catch(Exception e)
              e.printStackTrace();
                        // to do: code goes here.
                        out.println("<HTML>");
                        out.println("<HEAD><TITLE>Contractor TimeTracker</TITLE></HEAD>");
                        out.println("<BODY>");
                        // to do: your HTML goes here.
                        out.println("</BODY>");
                        out.println("</HTML>");
                        out.close();
              

              I came across this kind of problem once. My problem went away after I upgraded
              from 5.1 SP6 to 5.1 SP8.
              "Dharma" <[email protected]> wrote:
              >
              >Hi,
              >
              >I am working on J2EE applications.I am using Webgain studio and weblogic
              >server.I
              >got a problem while invoking EJB from the servlet.
              >
              >While calling an EJB from the servlet, it is giving that "Class Cast
              >Exception".This
              >is because, the remote home reference is not able to type casted to the"Home
              >Interface"
              >of the EJB, even if I type casted explicitly. It is creating the context
              >and able
              >to identify the EJB with the JNDI name.
              >
              >Could please help me in solving this problem.I am pasting the code here.
              >
              >Thanks in advance,
              >Dharma
              >
              >
              >public void doGet(HttpServletRequest req, HttpServletResponse resp)
              >     throws ServletException, IOException
              >     {
              >          resp.setContentType("text/html");
              >          PrintWriter out = new PrintWriter(resp.getOutputStream());
              >
              > try
              > {
              >
              > Context context=getInitialContext();
              >
              > Object reference=context.lookup("ArlProjContractorAppletSession");
              >
              > ArlProjContractorAppletSessionHome home=(ArlProjContractorAppletSessionHome)PortableRemoteObject.narrow(reference,ArlProjContractorAppletSessionHome.class);
              >
              >//Exception is occuring in the above statement. It is unable
              >//to cast to the home interface          
              >
              >          ArlProjContractorAppletSession the_ejb=null;
              >
              > try
              > {
              > the_ejb=home.create();
              >
              > System.out.println("the_ejb = " + the_ejb.toString());
              >
              > }
              > catch(Exception e)
              > {
              > e.printStackTrace();
              > }
              > }
              > catch(Exception e)
              > {
              > e.printStackTrace();
              > }
              >          // to do: code goes here.
              >
              >          out.println("<HTML>");
              >          out.println("<HEAD><TITLE>Contractor TimeTracker</TITLE></HEAD>");
              >          out.println("<BODY>");
              >
              >          // to do: your HTML goes here.
              >
              >          out.println("</BODY>");
              >          out.println("</HTML>");
              >          out.close();
              >     }
              >
              >
              >
              >
              >
              

  • Javax.ejb.Inject not found

    I'm working with jdeveloper 10.1.3 in S.O. XP
    build a proyect template JSP,EJB3,TOPLINK
    import javax.ejb.Inject;
    Error: Inject not found
    Tanks

    Add EJB 3.0 Library to project libraries.

  • Accessing EJBs from a servlet

    Hi everyone,
    I deployed my EJB component in an Oracle 8.1.7 database and I try to access it from a servlet.
    If I run my servlet from JDeveloper 3.2 (Web-to-Go), it all works fine. If I run my servlet from JRun 3.01 or from Tomcat 3.2.1, I get the following exception:
    javax.naming.NoInitialContextException: Need to specify class name in environmen
    t or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
    at java.lang.Throwable.fillInStackTrace(Native Method)
    at java.lang.Throwable.fillInStackTrace(Compiled Code)
    at java.lang.Throwable.<init>(Compiled Code)
    at java.lang.Exception.<init>(Compiled Code)
    at javax.naming.NamingException.<init>(NamingException.java:104)
    at javax.naming.NoInitialContextException.<init>(NoInitialContextException.java:58)
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:649)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:242)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:279)
    at javax.naming.InitialContext.lookup(InitialContext.java:349)
    at com.cognicase.framework.base.U0003.AbstractORB.getBean(AbstractORB.java:285)
    at com.cognicase.framework.base.U0003.AbstractORB.getBean(Compiled Code)
    at com.cognicase.demo.U2007BL.U2007WP_Users.lookupBean(U2007WP_Users.java:60)
    at com.cognicase.framework.is.U0103.AbstractBeanWrapper.beforeBeanCall(AbstractBeanWrapper.java:121)
    at com.cognicase.demo.U2007BL.U2007WP_Users.valideUser(U2007WP_Users.java:77)
    at com.cognicase.demo.U2000WB.U2000MW_WorkSpace.CallEjb(Compiled Code)
    at com.cognicase.demo.U2000WB.U2000MW_WorkSpace.doValidateLogin(Compiled Code)
    at com.cognicase.demo.U2000WB.U2000MW_WorkSpace.processService(U2000MW_WorkSpace.java:98)
    at Demo_0100_01.service(Demo_0100_01.java:128)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
    at org.apache.tomcat.core.Handler.service(Compiled Code)
    at org.apache.tomcat.core.ServletWrapper.service(Compiled Code)
    at org.apache.tomcat.core.ContextManager.internalService(Compiled Code)
    at org.apache.tomcat.core.ContextManager.service(Compiled Code)
    at org.apache.tomcat.service.connector.Ajp13ConnectionHandler.processConnection(Compiled Code)
    at org.apache.tomcat.service.TcpWorkerThread.runIt(Compiled Code)
    at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(Compiled Code)
    at java.lang.Thread.run(Compiled Code)
    If I add my servlet classes, aurora_client.jar, mts.jar, vbjapp.jar and vbjorb.jar files to the CLASSPATH, it works fine.
    The behavior is the same in JRun and Tomcat.
    I don't like this solution since I have to make the CLASSPATH point to my application classes at the web server level instead of at the application context level.
    Has anyone been able to solve this problem?
    Thanks for your help.
    null

    Yes, I did. Actually, if I run my servlet in JDeveloper (Web-to-Go), it all works fine. I also extracted the code that calls the EJB from the servlet and I tested it in a small Java application, and it also works fine.
    Things stop to work when I deploy my servlet in JRun or in Tomcat.
    It appears that my code is correct, but the environment I try to run it is not, and I can't figure out what's wrong.
    Can anyone help me?
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Sandeep Desai ([email protected]):
    Have you provided the environmental settings in the servlet.
    It should be :
    import oracle.aurora.jndi.sess_iiop.ServiceCtx;
    env.put(Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");
    env.put(Context.SECURITY_PRINCIPAL, username);
    env.put(Context.SECURITY_CREDENTIALS, password);
    env.put(Context.SECURITY_AUTHENTICATION, ServiceCtx.NON_SSL_LOGIN);
    InitialContext ctx = new InitialContext(env);
    Object obj = ctx.lookup("test/EJBHome");
    HomeObject home = PortableRemoteObject.narrow(
    obj,"HomeObject.class");
    RemoteObject remote = home.create();
    This should make it work!!
    <HR></BLOCKQUOTE>
    null

  • @EJB injection fails in 11gR1?

    Hi !
    I can't get the @EJB injection to work on 11g R1. Is there any known issues?
    I tried this example : http://glassfish.java.net/javaee5/ejb/examples/Sless.html
    but the Weblogic server only gives NullpointerExeption.
    Is there any additional code that need to be added ?
    Regards, reZer

    Hi,
    I am having exactly the same problem with my application.
    Have your resolved this and how. I think may be the EJB jar
    is not being deployed. The Java naming directory interface(JNDI)
    to which you used the initialiseContext to insert the works for me too.
    But the @EJB injection does not work. You provided the JNDI name
    for Accountcontroller and that works but it won't work with injection.
    You only provide the client with the JNDI of the session bean only
    if you are using a stand alone client. But if you are running the client
    as an application client, you need to use the @EJB injection.
    I am also stack looking for solution.
    Thanks
    eve

  • EJB injection not working for a Jersey class

    I have a standard EJB3.0 bean defined as follows:
    @Stateless
    @Local(CustomerService.class)
    public class CustomerBean implements CustomerService
    I can successfully reference that EJB using dependency injection from a servlet with the following code:
    public class CustomerServlet extends HttpServlet {
    @EJB(beanName="CustomerBean")
    private CustomerService customerService;
    public void doGet(...) {
    CustomerVO customer = customerService.getCustomerById(id);
    However the same code will not work from a Jersey RESTful service class
    @Path("/{customer}")
    public class CustomerREST {
    @EJB(beanName="CustomerBean")
    private CustomerService customerService;
    @GET
    @Produces("text/plain")
    public String getCustomer(@PathParam("customer") String customerId) {
    CustomerVO customer = customerService.getCustomerById(customerId);
    The Jersey RESTful service class will get executed but throws a NullPointerException because the customerService entity is null.
    The CustomerServlet and the CustomerREST classes are both in the same WebApp, inside an EAR with the EJB.
    They are even in the same package!
    I would appreciate any help.

    Congratulations. You've hit the major limitation of JEE-based dependency injection. You can only inject resources into servlets, filters, listeners, and tag handlers. This is why people eventually move to Spring if they really need dependency injection in non-JEE components.
    You can read the WebLogic manual pages related to this at [http://download.oracle.com/docs/cd/E12840_01/wls/docs103/pdf/webapp.pdf] . Read chapter 8, "WebLogic Annotation for Web Components".

  • Best Practice for EJB calls from servlet?

    Hi folks
    I could not find general rules for making calls to an stateful EJB from the web container (e.g. from a backingBean). In some books they say it is a bad programming style calling them directly from a common servlet. The book says create first an HTTPSession Object and from there call the stateful EJB.
    I'm a bit confused because, I'm missing some best practice guide from where to initiate such calls.
    Can somebody please point me in the right direction?
    Kind Regards
    Bruno
    Edited by: zajoho on Oct 30, 2008 11:14 PM

    Hi Bruno,
    The main issue with the combination of stateful session beans and servlets is the servlet threading model.
    It is dangerous to store a stateful session bean reference in servlet instance state, since the servlet instance
    can be accessed concurrently, yet a stateful session bean reference is intended to be used by only one
    client.
    As you point out, one alternative is to store the reference in the HttpSession. That associates the reference
    with a particular client, which matches the stateful session bean programming model.

  • How can I call EJB from JSP/Servlets in iWS?

    Hi!!
    My JSP/Servlets are on iWS, and I deploy EJB on iAS.
    In this case, I don't know how JSP/Servlet call EJb on iAS.
    I'd like to know how I can set JNDI name in JSP/Servlet on iWS.
    I will thank you if you give me a simple example source using JSP/Servlet
    and EJB.
    Thanks in advance!!!
    - Park-

    Park,
    Why Are you running your JSP/Servlets in iWS instead of iAS? For whatever
    reason,
    look at the Converter sample from iAS. You will be doing RMI/IIOP in this
    case and the sample explains in detail what to do.
    hth,
    -robert
    "SungHyun, Park" <[email protected]> wrote in message
    news:9jpfmt$[email protected]..
    Hi!!
    My JSP/Servlets are on iWS, and I deploy EJB on iAS.
    In this case, I don't know how JSP/Servlet call EJb on iAS.
    I'd like to know how I can set JNDI name in JSP/Servlet on iWS.
    I will thank you if you give me a simple example source using JSP/Servlet
    and EJB.
    Thanks in advance!!!
    - Park-

  • Accessing an ejb from a servlet gives resource not allowed exception

    hi friends,
    i deployed a bean in weblogic server calling from within a servlet. this bean is used to retrieve a database connection and returns to the servlet. i have done all the resource references lookups everything and also the bean is deployed successfully, but when i run the servlet i didn't get even the println messages. it gives resource not allowed message.
    here is the deployment descriptor is correct ? if anything wrong or missed, please mention and try to give me the solution.
    web.xml
    <web-app>
    <servlet>
    <servlet-name>TestConnection</servlet-name>
    <display-name>TestConnection</display-name>
    <servlet-class>tms.com.ejb.TestConnection</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>TestConnection</servlet-name>
    <url-pattern>TestConnection</url-pattern>
    </servlet-mapping>
    <resource-ref>
    <res-ref-name>tmsPool</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
    <env-entry>
    <env-entry-name>tmsDataSource</env-entry-name>
    <env-entry-value>tmsPool</env-entry-value>
    <env-entry-type>java.lang.String</env-entry-type>
    </env-entry>
    <env-entry>
    <env-entry-name>TMS_DBConnectionBean</env-entry-name>
    <env-entry-value>java:comp/env/ejb/TMS_DBConnectionBean</env-entry-value>
    <env-entry-type>java.lang.String</env-entry-type>
    </env-entry>
    <ejb-ref>
    <ejb-ref-name>ejb/TMS_DBConnectionBean</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <home>tms.com.ejb.TMS_DBConnectionHome</home>
    <remote>tms.com.ejb.TMS_DBConnection</remote>
    <ejb-link>TMS_DBConnectionBean</ejb-link>
    </ejb-ref>
    </web-app>
    Ejb jar is
    <enterprise-beans>
    <session>
    <display-name>ConnectionBean</display-name>
    <ejb-name>TMS_DBConnectionBean</ejb-name>
    <home>tms.com.ejb.TMS_DBConnectionHome</home>
    <remote>tms.com.ejb.TMS_DBConnection</remote>
    <ejb-class>tms.com.ejb.TMS_DBConnectionBean</ejb-class>
    <session-type>Stateless</session-type>
    <transaction-type>Container</transaction-type>
    <env-entry>
    <env-entry-name>tmsDataSource</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>tmsPool</env-entry-value>
    </env-entry>
    <security-identity>
    <description></description>
    <use-caller-identity></use-caller-identity>
    </security-identity>
    <resource-ref>
    <res-ref-name>tmsPool</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    <!--<res-sharing-scope>Shareable</res-sharing-scope>-->
    </resource-ref>
    </session>
    </enterprise-beans>
    <weblogic-ejb-jar>
    weblogic ejb jar file is the following content.
    <weblogic-enterprise-bean>
    <ejb-name>TMS_DBConnectionBean</ejb-name>
    <stateless-session-descriptor>
    <pool>
         <max-beans-in-free-pool>1</max-beans-in-free-pool>
    </pool>
    </stateless-session-descriptor>
    <jndi-name>TMS_DBConnectionBean</jndi-name>
    </weblogic-enterprise-bean>
    thanx in advance..

    hi
    i tried the same but still i'm getting the same problem, the value i mentioned in the servlet lookup is java:comp/env/TMS_DBConnectionBean.
    then the value returned by the lookup would be java:comp/env/ejb/TMS_DBConnectionBean. right. Anyway i tried the same as u mentioned. that same problem resource not allowed is displayed in the browser. is there any other alternative to solve this?
    thanks

  • Web Service @EJB injection isn't working

    I'm running WebLogic Server 10.0 MP1
    I have a local interface:
    @Local
    public interface Login {
         boolean loginUser( String username, String password );
    }And an implementation:
    @Stateless
    @Local
    public class LoginBean implements Login {
         public boolean loginUser(String username, String password) {
              if (username != null && password != null && username.equals("test")
                        && password.equals("password")) {
                   return true;
              return false;
    }Those are bundled up in service.jar
    I also have a Web Service:
    @Stateless
    @WebService(name = "LoginService", targetNamespace = "http://my.namespace/here")
    @WLHttpTransport(contextPath = "services", serviceUri = "LoginService")
    public class LoginService {
         @EJB(name="bLogin")
         private Login login;
         @WebMethod
         public boolean login(String username, String password) {
              return login.loginUser(username, password);
    }The webservice is bundled into LoginService.war by the jswc ant task.
    LoginService.war and services.jar are together bundled into my .ear file with an appropriate application.xml, and the web console shows both the web service and EJB as being deployed with the EAR.
    When I access the LoginService, I always get a NullPointerException on the return login.loginUser() line (and a println indicates that in fact login is null).
    So WebLogic isn't injecting my bean into the login variable, however there are no warnings or errors on the console.
    I have seen http://forums.bea.com/thread.jspa?threadID=300003881 but that doesn't help, as my web.xml is generated by jswc and I verified that it always sets the version to 2.5 and namespace properly.
    One other interesting tidbit: If I set beanName to something crazy (like "foo") on the @EJB annotation in LoginService, I DO get an error (at deployment time) in the server log saying that the ejb-link for 'foo' wasn't found. So the lookup appears to be happening (though there is nothing about an ejb-link in the web.xml, I expect that it is implicitly happening at deploy time from the @EJB annotation) just not the actual injection.
    Thoughts?

    Since it looks like no one from BEA actually monitors these forums, I'll answer my own question.
    I no longer use the jswc ant task to generate LoginService.war. Now, I just drop my Login web service into its own jar file (apparently it doesn't work if it's in a JAR with other EJBs), say, ws.jar and put that into the EAR with everything else, and it works. Here is my web service now (called LoginImpl)
    @WebService(name = "Login", targetNamespace = MY_NAMESPACE)
    @SOAPBinding(style = Style.DOCUMENT, use = Use.LITERAL, parameterStyle = ParameterStyle.WRAPPED)
    @WLHttpTransport(contextPath = "services", serviceUri = "LoginService")
    @Stateless
    public class LoginImpl {
         @EJB(name = "Login")
         private Login login;
         @WebMethod(operationName="LoginRequest")
         @WebResult(name = "LoginResponse")
         public boolean login(
              @WebParam(name = "Username", targetNamespace = MY_NAMESPACE) String username,
              @WebParam(name = "Password", targetNamespace = MY_NAMESPACE) String password
              return login.loginUser( username, password );
         @WebMethod(operationName="LogoutRequest")
         @WebResult(name="LogoutResponse")
         public void logout( @WebParam(name = "SessionToken", targetNamespace = MY_NAMESPACE) String sessionToken ) {
              login.logoutUser( sessionToken );
    }So in summary:
    * Put @WebService files in their own JAR
    * Don't use jswc
    I also used Sun's JAX-WS reference implementation to generate the *.jaxwx.* files, otherwise WebLogic complains

  • How to call the EJB methods from servlet/jsp

    Hello ,
    i have write one ejb signOn having the method validateUser(username,password).i can able to call this function from client.java class.i want to know whether i can call this function from servlet.if yes then where to write that servlet and web.xml file.
    At present i m using weblogic server 8.1and i create directory call c:\ejb\demo and put the ejb files(home ,remote,ejb class ,client.java) then i have created .jar file and put in application file.
    Now i want to create a servlet for that i have to create a new directory and put the servlet,web.xml,weblogin-web.xml file and then create one .war file and put in application directory or do some thing extra.Please help me.
    Thanks In Advance
    [email protected]

    I think this might not be the most appropriate forum for your question. You might try a forum about ejb, or weblogic, or jndi.

  • Best practice for @EJB injection in junit test (out-of-container) ?

    Hi all,
    I'd like to run a JUnit test for a Stateless bean A which has another bean B injected via the @EJB annotation. Both beans are pure EJB 3 POJOs.
    The JUnit test should run out-of-container and is not meant to be an EJB client, either.
    What is the easiest/suggested way of getting this injection happening without explicitely having to instantiate the bean B in my test setup ?

    you can deal with EntityBeans without having the Container managed senario , you can obtain instance of EntityManager using the "EntityManagerFactory" and providing the "persistence.xml" file and provide the "provider" (toplink,hibernate ,...), then you can use entities as plain un managed classes

Maybe you are looking for