Injection @EJB  x  InitialContextLookup

Hello all,
what is the "lookup" correspondent to this injection:
@EJB (mappedName="corbaname:iiop:jupiter:3700#ejb/package.HelloRemote")
Are the following lines?
InitialContext ic = new InitialContext();
HelloRemote hello = (HelloRemote) ic.lookup("corbaname:iiop:jupiter:3700#ejb/package.HelloWorld");
Why these lines dont work? The injection woks fine, but these lines produces an exception:
"javax.naming.NameNotFoundException [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]"
I'm trying for one week now to do this dynamic lookup without succeeding. Please, what am I missing?

If you're running within a Java EE component the portable way to retrieve the EJB is
to use a component environment lookup, not a direct global lookup. Just add a
name() attribute to your @EJB.
@EJB (name="myejbref", mappedName="corbaname:iiop:jupiter:3700#ejb/package.HelloRemote")
If the lookup is within an EJB, you can use SessionContext.lookup("myejbref");
Otherwise, instantiate the no-arg InitialContext and lookup ("java:comp/env/myejbref")
Whenever the code attempts to bypass the Java EE component environment, it opens
itself up to portability issues. In this case, we try to support many variations of
direct global JNDI lookups, but Remote 3.0 Interfaces are not direct CosNaming objects,
so lookup("corbaname:iiop:...") will not work.
If you have to pass a dynamic string to the lookup you can try the same approach as
is recommended for non-Java EE environments, where you create a special
InitialContext that is configured to point to a particular naming service :
https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#nonJavaEEwebcontainerRemoteEJB
--ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • How am I able to use an injected EJB in a Managed Bean Constructor?

    JSF 1.2
    EJB 3.0
    Glassfish v1
    Summary:
    Managed bean injected EJB is null when referencing EJB var in constructor.
    Details:
    In my managed bean, I have a constructor that tries to reference an injected EJB, such as:
    public class CustomerBean implements Serializable {
    @EJB private CustomerSessionRemote customerSessionRemote;
    public CustomerBean() {
    List<CustomerRow> results = customerSessionRemote.getCustomerList();
    }The call within the constructor to customerSessionRemote is null - I've double checked this in Netbeans 5.5.
    How am I able to use an injected EJB in a Managed Bean Constructor?
    Thanks,
    --Todd                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    OK, I was reading the article Web Tier to Go With Java EE 5: A Look at Resource Injection and I understand your statement too.
    Is there any way possible to Inject the EJB prior to the bean instance creation at all?
    Maybe, I need to approach it with the old fashion Java EE 1.4 route and using JNDI in the PostConstruct annotated method to reference the EJB in the managed bean.
    This had to been thought out before, I don't understand why a manged bean's life cycle places any injections at the end of the bean creation.
    Also, now that I understand that the @PostConstruct annotated method will be called by the container after the bean has been constructed and before any business methods of the bean are executed.
    I am trying to reference my EJB as part of the creation of the managed bean.
    What happens: the JSF page loads the managed bean and I need to populate a listbox component with data from an EJB.
    When I try to make the call to the EJB in the listbox setter method, the EJB reference is null.
    Now, I'm not for sure if the @PostConstruct annotation is going to work... hmmmm.
    ** Figured it out. ** I just needed to move the EJB logic that was still in the setter of the component I wanted to populate into the annotated PostConstruct method.

  • How to inject ejb in servlet

    hi all
    How to inject ejb in servlet ?
    please explain how to config my servlet and my paroject
    I have an ear file with two jar files
    Thanks in advance

    hi
    I have this error in my project
    I have an ear file ,two war file and three jar file in it
    and I did configuration
    but there was this error
    14:19:45,398 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[conference-servlet].[enterLet]] Allocate exception for servlet enterLet: javax.naming.NameNotFoundException: ITrmnlAuthenticationBL not bound
    @Remote
    public interface ITrmnlAuthenticationBL{
    @Stateless
    public class TrmnlAuthenticationBL implements ITrmnlAuthenticationBL{
    public class EnterLet extends HttpServlet {
         @EJB(mappedName = "ITrmnlAuthenticationBL")
         private ITrmnlAuthenticationBL trmnlMg;
    please explain my mistake

  • Best way to inject EJB's in Struts 2

    Hi all,
    I'd like to ask you what do you think is the best way to inject EJB's in Struts 2 Actions (and perhaps other struts classes such as type converters).
    I've read and implemented both a Struts 2 Interceptor and used CDI. About CDI I've read there's a discussion whether the injected resource should be a private field or injected through the constructor which would help testing.
    Personally I seem to prefer CDI as it looks a bit simpler after you are familiar a bit with the technology.
    What is your preferred solution and why?

    Make sure you are using JDeveloper with a "regular Oracle DB" and not Oracle XE - Oracle XE doesn't have support for JPublisher.
    And make sure you are trying to invoke this from the database navigator window and not from the connection manager of your application.
    Anton - I think you are mixing JPublisher with something else - maybe with Java stored procedures?
    JPublisher just creates a JDBC wrapper that calls the functions in the DB - it doesn't run inside the DB so I don't get your point about the mini JVM?
    So it basically does exactly what you recommended: "access PL/SQL procedures from java directly?"

  • Injecting EJB to JSF Converter

    Is it possible to inject EJB (or at least EntityManager) to JSF Converter or Validator?
    I don't know if i'm missing something or is it just impossible - it works when injecting EJB into Managed Bean.
    Thanks.
    S&#322;awek S.

    Slawek_Sobotka wrote:
    Thanks.
    So I'll redefine my question to be problem oriented:
    I have SelectItem that contains Address object.
    I have implemented AddressConverter so that it converts Adress to String simply by using it's id.
    How to convert back: from string (address's id) do Address object?Map it. Two general ways are mentioned here: [http://balusc.blogspot.com/2007/09/objects-in-hselectonemenu.html].
    I would like to load it form DB...That's a bit too expensive for less or more static data.
    Another solutions are:
    - SelectItem should contain address.id instead of address. Than no converter is need. My ManagedBean is reposnsible for translating ids do entities. Works but primitive.JSF can't help that HTTP/HTML only understands Strings (by the way, primitives are also already implicitly converted by EL, you only don't know that).
    - Converter is created by factory method of Managed Bean. MB sets address list to the converter while creating it. List shouldn't be huge if it is used in GUI.
    drawback: loading list in BB twice because converter is used while rendering and while decoding.
    - In converter try to possess MB that has EJB and call method that reutrns entities, sth like this: facesContext.getApplication().getELResolver()...Reloading static data on every request makes als no sense.
    Retoric question: what for are useful JSF Converters?To convert between Object and String, so that it can be passed through HTTP request/response and displayed/taken in HTML.

  • Problem injecting ejb in war

    This problem have dogged me for one week but cant seem to know where the problem is.
    i am creating an enterprise with war, ejb and jar.
    i want both web clients and application client to share the code in ejb to ease maintainablility.
    i have a jsf backing bean that is supposed to get some data from an enterprise bean in ejb.
    the backing bean has this method
    public class CategoryController {
    @Stateful
    public class CategoryControllerBean implements CategoryControllerRemote {
        @PersistenceUnit(unitName = "JNationForum-ejbPU")
        private EntityManagerFactory emf;
        private EntityManager getEntityManager() {
            return emf.createEntityManager();
    public List<CategoryDetails> getCategorys(){
             EntityManager em = getEntityManager();
             List<Category> categorys=null;
             try{
                Query q = em.createQuery("select object(o) from Category as o");
                return copyCategorysToDetails(categorys=q.getResultList());
            } finally {
                em.close();
         private List<CategoryDetails> copyCategorysToDetails(List categorys) {
            List<CategoryDetails> detailsList = new ArrayList<CategoryDetails>();
            Iterator i = categorys.iterator();
            while (i.hasNext()) {
                Category category = (Category) i.next();
                CategoryDetails details = new CategoryDetails(
                        category.getCategorypk(),
                        category.getTitle(),
                        category.getDescription(),
                        category.getActive());
                detailsList.add(details);
            return detailsList;
    }it brings this error
    type Exception report
    message
    descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException: com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref com.safarisoftsolutions.jnationforum.war.bean.CategoryController/categoryControllerBean@jndi: com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean@null@com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean@Session@null into class com.safarisoftsolutions.jnationforum.war.bean.CategoryController
    root cause
    javax.faces.FacesException: com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref com.safarisoftsolutions.jnationforum.war.bean.CategoryController/categoryControllerBean@jndi: com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean@null@com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean@Session@null into class com.safarisoftsolutions.jnationforum.war.bean.CategoryController
    root cause
    com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref com.safarisoftsolutions.jnationforum.war.bean.CategoryController/categoryControllerBean@jndi: com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean@null@com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean@Session@null into class com.safarisoftsolutions.jnationforum.war.bean.CategoryController
    root cause
    javax.naming.NameNotFoundException: com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean#com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean not found
    note The full stack traces of the exception and its root causes are available in the Sun Java System Application Server 9.1 logs.

    This problem have dogged me for one week but cant seem to know where the problem is.
    i am creating an enterprise with war, ejb and jar.
    i want both web clients and application client to share the code in ejb to ease maintainablility.
    i have a jsf backing bean that is supposed to get some data from an enterprise bean in ejb.
    the backing bean has this method.package com.safarisoftsolutions.jnationforum.war.bean;
    public class CategoryController {
        @EJB
        private CategoryControllerBean categoryControllerBean;
        public DataModel getCategorys() {
                model = new ListDataModel(categoryControllerBean.getCategorys());
                return model;
    }from the above you can see am trying to get a list from categoryControllerBean.getCategorys() which is a enterprise bean whose code is
    public class CategoryController {
    @Stateful
    public class CategoryControllerBean implements CategoryControllerRemote {
        @PersistenceUnit(unitName = "JNationForum-ejbPU")
        private EntityManagerFactory emf;
        private EntityManager getEntityManager() {
            return emf.createEntityManager();
    public List<CategoryDetails> getCategorys(){
             EntityManager em = getEntityManager();
             List<Category> categorys=null;
             try{
                Query q = em.createQuery("select object(o) from Category as o");
                return copyCategorysToDetails(categorys=q.getResultList());
            } finally {
                em.close();
         private List<CategoryDetails> copyCategorysToDetails(List categorys) {
            List<CategoryDetails> detailsList = new ArrayList<CategoryDetails>();
            Iterator i = categorys.iterator();
            while (i.hasNext()) {
                Category category = (Category) i.next();
                CategoryDetails details = new CategoryDetails(
                        category.getCategorypk(),
                        category.getTitle(),
                        category.getDescription(),
                        category.getActive());
                detailsList.add(details);
            return detailsList;
    }it brings this error
    type Exception report
    message
    descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException: com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref com.safarisoftsolutions.jnationforum.war.bean.CategoryController/categoryControllerBean@jndi: com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean@null@com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean@Session@null into class com.safarisoftsolutions.jnationforum.war.bean.CategoryController
    root cause
    javax.faces.FacesException: com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref com.safarisoftsolutions.jnationforum.war.bean.CategoryController/categoryControllerBean@jndi: com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean@null@com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean@Session@null into class com.safarisoftsolutions.jnationforum.war.bean.CategoryController
    root cause
    com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref com.safarisoftsolutions.jnationforum.war.bean.CategoryController/categoryControllerBean@jndi: com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean@null@com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean@Session@null into class com.safarisoftsolutions.jnationforum.war.bean.CategoryController
    root cause
    javax.naming.NameNotFoundException: com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean#com.safarisoftsolutions.jnationforum.ejb.bean.CategoryControllerBean not found
    note The full stack traces of the exception and its root causes are available in the Sun Java System Application Server 9.1 logs.

  • Inject EJB using @EJB in Servlet Filter on Weblogic 11g

    Hi All,
    I want to inject the EJB (Local interface) into the Servlet Filter and the EAR is deployed on Weblogic 11g.
    My question is:
    Shall the @EJB Annotation work on Weblogic 11g or it will be ignored in case of Servlet or Servlet Filter?
    OR
    I have to do look up as below and mention the references in web.xml and weblogic xml file:
    I know below code should be used when you have remote interface.
    Hashtable env = new Hashtable();
    env.put( Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory" );
    Context ctx = new InitialContext( env );
    ctx.lookup( "myejb" );
    Thanks

    Hi,
    It should work in 11g.
    Regards,
    Kal

  • Dependecy injection EJB into a jsp

    Hello,
    How can I do a dependency injection of and EJB into a jsp?
    When Iu2019m trying to used it (see below), It doesnu2019t work, What Iu2019m doing wrong?
    Also I tried to do a lookup, but I canu2019t do a cast because the classe returned by the lookup is some Proxy class and the only way that Iu2019ve find to access the EJBu2019s methods is through reflection.
    Regards,
    Janeth
    @EJB (name = "crystal.com.co/captura_produccion_ear/CapturaPrimeraEjbBean")
         private CapturaPrimeraEjbRemote capPrimeraEjbRemote;
    if (capPrimeraEjbRemote != null) {
           capPrimeraEjbRemote.test();
    else{
              out.println("null");

    Thank both for the answer, about the lookup:
    Vladimir you are right about implementation, actually I print trough reflection the interfaces of Proxy class, and I obtain this:
    co.com.crystal.eficiencia.primera.CapturaPrimeraEjbRemote
    javax.ejb.EJBObject
    com.sap.engine.services.ejb3.runtime.ComponentInterface com.sap.engine.services.ejb3.runtime.ReplaceableProxy
    The common code is:
    Properties props = new Properties();
         props.put(Context.INITIAL_CONTEXT_FACTORY,
                   "com.sap.engine.services.jndi.InitialContextFactoryImpl");
         props.put(Context.PROVIDER_URL, "localhost:50004");
         InitialContext ctx = new InitialContext(props);
         Object object = ctx.lookup("crystal.com.co/captura_produccion_ear/REMOTE/CapturaPrimeraEjbBean/co.com.crystal.eficiencia.primera.CapturaPrimeraEjbRemote");
         out.println(object.getClass());
    If I do injection, itu2019s work correctly:
    Method findAll = object.getClass().getMethod("test", null);
         String listaTurnos = (String) findAll.invoke(object, null);
         out.print(listaTurnos);
    But if I use narrow or cast, it doesnu2019t work (I get a java.lang.ClassCastException):
    co.com.crystal.eficiencia.primera.CapturaPrimeraEjbRemote capPrimera = (co.com.crystal.eficiencia.primera.CapturaPrimeraEjbRemote)PortableRemoteObject.narrow(object, co.com.crystal.eficiencia.primera.CapturaPrimeraEjbRemote.class);
         String listaTurnos = capPrimera.test
         out.print(listaTurnos);
    or the cast:
    co.com.crystal.eficiencia.primera.CapturaPrimeraEjbRemote capPrimera = (co.com.crystal.eficiencia.primera.CapturaPrimeraEjbRemote)object;
    What I have to do to check the correctly way to do the cast or the narrow? What Iu2019m doing wrong?
    Thanks
    Janeth

  • Injecting ejb impossible using deployment descriptor ?

    Hi.
    I wanted to inject an EJB reference into a JSF manged bean. @EJB annotation worked, but then I tried <ejb-reb> and <injection-target> and EJB reference wasn't injected.
    Looking at the specification, it seems that this is not supported. Is there any other possibility or am I forced to use annotations?

    Hi.
    I wanted to inject an EJB reference into a JSF manged bean. @EJB annotation worked, but then I tried <ejb-reb> and <injection-target> and EJB reference wasn't injected.
    Looking at the specification, it seems that this is not supported. Is there any other possibility or am I forced to use annotations?

  • Injecting ejbs via @Resource

    Hi all,
    I have an ejb that injects a helper ejb like
    @EJB
    Helper help; and whose business method calls the helper beans business method. This works fine.
    Now I try to inject the helper ejb as
    @Resource(name="Helper") 
    Helper help; The first call of the ejb's business method from the client works fine, but the second one throws the following exception (extract):
    org.omg.CORBA.BAD_OPERATION: The delegate has not been set!
    Please, can someone, who has an ejb that injects another ejb, check if he gets the same problem when @EJB is replaced through something like @Resource(name = ...).
    Thanks in advance.
    I googled for the error message and found search results dating from around 2004 where the error was due to a bug in the Java-IDL mapping of an old java version. I'm working with glassfish v2 and java 1.6.

    Hi, thanks for your reply.
    Is there a particular behavior you would like that you don't think is available when using @EJB?No. I read in "EJB 3 in action", 5.2.1 that @Resource can "be used for [...] environment entries, ORB reference and even EJB references" and just tried it out.

  • Is it possible to inject EJB 3.0 SLSB into EntityImpl?

    Hello,
    I'm running JDev Studio Edition Version 11.1.2.3.0.
    Is it possible to inject an EJB 3.0 stateless session bean into an EntityImpl Class via the @EJB annotation? I need to do so in order to use the SLSB to schedule an EJB 3.0 timer.
    If injection is not possible, how do I do a manual lookup?
    Any suggestions with sample config and code would be appreciated.
    Many thanks.

    So you're saying that there are going to be new features in the released product that have not been tested in a beta release? I can't believe you'd go to release without another public beta considering the number of bugs there are in the current public beta never mind what else might be introduced by new features. That aside I appreciate the work of the developers.
    Also, I've seen several posts that refer to bug tracking ids. Where is the bug database? It's hard to know if a bug should be submitted here on this board without knowing which bugs have already been identified. With JDeveloper now available for use by the masses, a public database is essential to keeping message board traffic manageable. An RSS feed for the bug database would be an excellent feature.

  • Injected @EJB not working correctly???

    I developed a simple J2EE Project using Netbeans 5.5.
    I have the following EJB's:
    - ShoppingCartBean.java (Stateful Session Bean)
    - ShoppingCartLocal.java
    - Product.java (Entity Bean)
    - ProductFacade.java
    - ProductFacadeLocal.java
    The ShoppingCartBean.java has the basic structure:
    @Stateful
    public class ShoppingCartBean implements ShoppingCartLocal {
    @EJB
    private ProductFacadeLocal productFacade;
    public void addProduct( String id ) {
    Product product = productFacade.find( id );
    HOWEVER, when I try and run the app, I get the following error:
    Deploying application in domain failed; Error loading deployment descriptors for module [help2] -- This bean [ShoppingCartBean] has no ejb reference by the name of [productFacade]
    I believe that the error is caused by the file < sun-ejb-jar.xml >. Here are the contents of that file:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 EJB 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-0.dtd">
    <sun-ejb-jar>
    <enterprise-beans>
    <ejb>
    <ejb-name>ShoppingCartBean</ejb-name>
    <ejb-ref>
    <ejb-ref-name>productFacade</ejb-ref-name>
    <jndi-name>ejb/productFacade</jndi-name>
    </ejb-ref>
    </ejb>
    </enterprise-beans>
    </sun-ejb-jar>
    CAN ANYBODY PLEASE HELP???
    If you're really good with J2EE, here's the error stack trace:
    ADM1064:The upload file at [C:\Documents and Settings\Joel Martin\Local Settings\Temp\s1astempdomain1server1142715591\help2.ear] exists and will be overwritten.
    ADM1006:Uploading the file to:[C:\Documents and Settings\Joel Martin\Local Settings\Temp\s1astempdomain1server1142715591\help2.ear]
    Exception occured in J2EEC Phase
    com.sun.enterprise.deployment.backend.IASDeploymentException: Error loading deployment descriptors for module [help2] -- This bean [ShoppingCartBean] has no ejb reference by the name of [productFacade]
    at com.sun.enterprise.deployment.backend.Deployer.loadDescriptors(Deployer.java:362)
    at com.sun.enterprise.deployment.backend.AppDeployerBase.loadDescriptors(AppDeployerBase.java:327)
    at com.sun.enterprise.deployment.backend.AppDeployer.explodeArchive(AppDeployer.java:332)
    at com.sun.enterprise.deployment.backend.AppDeployer.deploy(AppDeployer.java:182)
    at com.sun.enterprise.deployment.backend.AppDeployer.doRequestFinish(AppDeployer.java:129)
    at com.sun.enterprise.deployment.phasing.J2EECPhase.runPhase(J2EECPhase.java:169)
    at com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPhase.java:95)
    at com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeploymentService.java:871)
    at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:266)
    at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:739)
    at com.sun.enterprise.management.deploy.DeployThread.deploy(DeployThread.java:174)
    at com.sun.enterprise.management.deploy.DeployThread.run(DeployThread.java:210)
    Caused by: java.lang.IllegalArgumentException: This bean [ShoppingCartBean] has no ejb reference by the name of [productFacade]
    at com.sun.enterprise.deployment.EjbDescriptor.getEjbReference(EjbDescriptor.java:1459)
    at com.sun.enterprise.deployment.node.runtime.EjbRefNode.setElementValue(EjbRefNode.java:78)
    at com.sun.enterprise.deployment.node.SaxParserHandler.endElement(SaxParserHandler.java:408)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:633)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLNSDTDValidator.endNamespaceScope(XMLNSDTDValidator.java:260)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleEndElement(XMLDTDValidator.java:2059)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement(XMLDTDValidator.java:932)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanEndElement(XMLNSDocumentScannerImpl.java:719)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1685)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:375)
    at com.sun.enterprise.deployment.io.DeploymentDescriptorFile.read(DeploymentDescriptorFile.java:279)
    at com.sun.enterprise.deployment.archivist.Archivist.readRuntimeDeploymentDescriptor(Archivist.java:514)
    at com.sun.enterprise.deployment.archivist.ApplicationArchivist.readRuntimeDeploymentDescriptor(ApplicationArchivist.java:387)
    at com.sun.enterprise.deployment.backend.Deployer.loadDescriptors(Deployer.java:320)
    ... 11 more
    |#]
    null

    Yikes, I wish that I knew what you know. I've tried just about everything possible, and exhaustively searched the internet for a solution, but to no avail.
    If you have any free time, can you please look at my classes, and fix whatever I've done wrong? Thanks.
    The exception is thrown in the file Product.java in the statement:
    if ( productFacade == null )
    throw new RuntimeException("Unable to use ProductFacadeLocal");
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    // AddToCartServlet.java
    // AddToCartServlet adds a Product to the Customer's
    // ShoppingCart.
    package servlets;
    import beans.ShoppingCartBean;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.Collection;
    import java.util.Iterator;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    import model.ProductModel;
    public class AddToCartServlet extends HttpServlet {
    // respond to HTTP get requests
    public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
    //get the session
    HttpSession session = request.getSession();
    //get the shoppingCart
    ShoppingCartBean shoppingCart = ( ShoppingCartBean ) session.getAttribute( "cart" );
    //get the input ID
    String id = request.getParameter( "ID" );
    //set up the output html
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Servlet AddToCartServlet</title>");
    out.println("</head>");
    out.println("<body>");
    //if no shopping cart, then create new
    if ( shoppingCart == null ) {
    shoppingCart = new ShoppingCartBean();
    session.setAttribute( "cart", shoppingCart );
    //add the item to the shopping cart
    shoppingCart.addProduct( id );
    //output all of the shopping cart items.
    Collection c = shoppingCart.getContents();
    for ( Iterator i = c.iterator(); i.hasNext(); ) {
    ProductModel pm = (ProductModel) i.next();
    out.println("<h1>"+pm.getId()+"|"+pm.getTitle()+"</h1>");
    //finish the html
    out.println("</body>");
    out.println("</html>");
    out.close();
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    // ProductModel.java
    // ProductModel represents a Product,
    // including id and title.
    package model;
    import java.io.Serializable;
    public class ProductModel implements Serializable {
    // ProductModel properties
    private String id;
    private String title;
    public String getId() {
    return id;
    public void setId(String id) {
    this.id = id;
    public String getTitle() {
    return title;
    public void setTitle(String title) {
    this.title = title;
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    package beans;
    import entity.Product;
    import entity.ProductFacadeLocal;
    import java.util.ArrayList;
    import java.util.Collection;
    import javax.ejb.EJB;
    import javax.ejb.Stateful;
    @Stateful
    public class ShoppingCartBean implements ShoppingCartLocal {
    @EJB
    private ProductFacadeLocal productFacade;
    private Collection orderProductModels;
    /** Creates a new instance of ShoppingCartBean */
    public ShoppingCartBean() {
    orderProductModels = new ArrayList();
    //get the shopping cart contents
    public Collection getContents() {
    return orderProductModels;
    //add a product to the shopping cart
    public void addProduct( String id ) {
    //first get a reference to the product entity bean
    if ( productFacade == null )
    throw new RuntimeException("Unable to use ProductFacadeLocal");
    //find the item using it's primary key (id)
    Product product = productFacade.find(id);
    //if the product isn't found, then throw exception
    if ( product == null )
    throw new RuntimeException("Product not found with id = "+id);
    //add product to collection
    orderProductModels.add( product.getProductModel() );
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    // ShoppingCartLocal.java
    package beans;
    import java.util.Collection;
    * This is the business interface for ShoppingCart enterprise bean.
    public interface ShoppingCartLocal {
    Collection getContents();
    void addProduct(String id);
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    //Product.java
    package entity;
    import java.io.Serializable;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import model.ProductModel;
    @Entity
    public class Product implements Serializable {
    @Id
    private String id;
    private String title;
    /** Creates a new instance of HelpEntity */
    public Product() {
    public String getId() {
    return id;
    public void setId(String id) {
    this.id = id;
    public String toString() {
    //TODO change toString() implementation to return a better display name
    return "" + this.getId();
    public String getTitle() {
    return title;
    public void setTitle(String title) {
    this.title = title;
    public ProductModel getProductModel() {
    ProductModel pm = new ProductModel();
    pm.setId(id);
    pm.setTitle(title);
    return pm;
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    //ProductFacade.java
    package entity;
    import java.util.List;
    import javax.ejb.Stateless;
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
    @Stateless
    public class ProductFacade implements ProductFacadeLocal {
    @PersistenceContext
    private EntityManager em;
    /** Creates a new instance of ProductFacade */
    public ProductFacade() {
    public void create(Product product) {
    em.persist(product);
    public void edit(Product product) {
    em.merge(product);
    public void destroy(Product product) {
    em.merge(product);
    em.remove(product);
    public Product find(Object pk) {
    return (Product) em.find(Product.class, pk);
    public List findAll() {
    return em.createQuery("select object(o) from entity.Product as o").getResultList();
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    //ProductFacadeLocal.java
    package entity;
    import java.util.List;
    public interface ProductFacadeLocal {
    void create(Product product);
    void edit(Product product);
    void destroy(Product product);
    Product find(Object pk);
    List findAll();
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    sun-ejb-jar.xml
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 EJB 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-0.dtd">
    <sun-ejb-jar>
    <enterprise-beans/>
    </sun-ejb-jar>
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    null

  • @EJB annotation for injection and lazy relations

    Hi,
    I develop a ejb3/jsf application.
    I have lazy relations in my entity beans.
    I remark that in my managed bean of my JSF, if I use @EJB annotation to inject session bean, I have no problem on lazy on entity beans returned by this session bean.
    Example
    JsfManageBean{
    @EJB
    Bean sessionBean ...
    public void doSomething(){
    Department d = sessionBean.findDepartmentBy...
    // relation lazy
    d.getEmployees()
    -> Load of employees -> NO LAZY PROBLEM !
    Someone can explain me why it works ?
    For me, after the find method, my session is closed !
    If I do a lookup to find my session bean (and so no injection @EJB here) -> I HAVE THE LAZY PROBLEM !
    public void doSomething(){
    SessionBean = ... context.lookup("blablabla")
    Department d = sessionBean.findDepartmentBy...
    // relation lazy
    d.getEmployee()
    -> LAZY EXCEPTION
    thanks for help !

    Nobody please ?

  • Ejb 3 Dependency Injection and Deployment

    Dear all,
    I have two project. one is ejb_jar and another is ear.
    both deploy in same weblogic server with separate package.
    But i can't use DI with separate package.
    Why i can't use DI with separate package. it dosen't support?
    Or my code is wrong?
    ///// session bean
    @Stateless(name = "SessionEJB", mappedName = "stars21_web-Model-SessionEJB")
    @Remote
    @Local
    public class SessionEJBBean implements SessionEJB, SessionEJBLocal
    ///// client injection
    @EJB
    SessionEJB test;
    With Regards,
    WP

    These are my full log
    NFO: Cleaning up application state
    <Nov 4, 2009 5:23:49 PM SGT> <Error> <Deployer> <BEA-149265> <Failure occurred in the execution of deployment request with ID '1257326626033' for task '6'. Error is: 'weblogic.application.ModuleException: Could not setup environment'
    weblogic.application.ModuleException: Could not setup environment
         at weblogic.servlet.internal.WebAppModule.activateContexts(WebAppModule.java:1361)
         at weblogic.servlet.internal.WebAppModule.activate(WebAppModule.java:408)
         at weblogic.application.internal.flow.ModuleStateDriver$2.next(ModuleStateDriver.java:182)
         at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:37)
         at weblogic.application.internal.flow.ModuleStateDriver.activate(ModuleStateDriver.java:48)
         Truncated. see log file for complete stacktrace
    weblogic.deployment.EnvironmentException: [J2EE:160200]Error resolving ejb-ref 'sg.com.stee.stars21.testing.Servlet1/registrationAuthorityFacade' from module 'stars21_web-stars21-context-root' of application 'stars21_web'. The ejb-ref does not have an ejb-link and the JNDI name of the target bean has not been specified. Attempts to automatically link the ejb-ref to its target bean failed because no EJBs in the application were found to implement the 'sg.com.stee.stars21.common.facade.RegistrationAuthorityFacade' interface. Please link or map this ejb-ref to its target EJB and ensure the interfaces declared in the ejb-ref are correct.
         at weblogic.deployment.BaseEnvironmentBuilder.autowireEJBRef(BaseEnvironmentBuilder.java:426)
         at weblogic.deployment.EnvironmentBuilder.addEJBReferences(EnvironmentBuilder.java:465)
         at weblogic.servlet.internal.CompEnv.activate(CompEnv.java:157)
         at weblogic.servlet.internal.WebAppServletContext.activate(WebAppServletContext.java:3034)
         at weblogic.servlet.internal.WebAppModule.activateContexts(WebAppModule.java:1359)
         Truncated. see log file for complete stacktrace
    >
    <Nov 4, 2009 5:23:49 PM SGT> <Error> <Deployer> <BEA-149202> <Encountered an exception while attempting to commit the 9 task for the application 'stars21_web'.>
    <Nov 4, 2009 5:23:49 PM SGT> <Warning> <Deployer> <BEA-149004> <Failures were detected while initiating deploy task for application 'stars21_web'.>
    <Nov 4, 2009 5:23:49 PM SGT> <Warning> <Deployer> <BEA-149078> <Stack trace for message 149004
    weblogic.application.ModuleException: Could not setup environment
         at weblogic.servlet.internal.WebAppModule.activateContexts(WebAppModule.java:1361)
         at weblogic.servlet.internal.WebAppModule.activate(WebAppModule.java:408)
         at weblogic.application.internal.flow.ModuleStateDriver$2.next(ModuleStateDriver.java:182)
         at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:37)
         at weblogic.application.internal.flow.ModuleStateDriver.activate(ModuleStateDriver.java:48)
         Truncated. see log file for complete stacktrace
    weblogic.deployment.EnvironmentException: [J2EE:160200]Error resolving ejb-ref 'sg.com.stee.stars21.testing.Servlet1/registrationAuthorityFacade' from module 'stars21_web-stars21-context-root' of application 'stars21_web'. The ejb-ref does not have an ejb-link and the JNDI name of the target bean has not been specified. Attempts to automatically link the ejb-ref to its target bean failed because no EJBs in the application were found to implement the 'sg.com.stee.stars21.common.facade.RegistrationAuthorityFacade' interface. Please link or map this ejb-ref to its target EJB and ensure the interfaces declared in the ejb-ref are correct.
         at weblogic.deployment.BaseEnvironmentBuilder.autowireEJBRef(BaseEnvironmentBuilder.java:426)
         at weblogic.deployment.EnvironmentBuilder.addEJBReferences(EnvironmentBuilder.java:465)
         at weblogic.servlet.internal.CompEnv.activate(CompEnv.java:157)
         at weblogic.servlet.internal.WebAppServletContext.activate(WebAppServletContext.java:3034)
         at weblogic.servlet.internal.WebAppModule.activateContexts(WebAppModule.java:1359)
         Truncated. see log file for complete stacktrace
    >
    [05:23:49 PM] Weblogic Server Exception: weblogic.application.ModuleException: Could not setup environment
    [05:23:49 PM] Caused by: weblogic.deployment.EnvironmentException: [J2EE:160200]Error resolving ejb-ref 'sg.com.stee.stars21.testing.Servlet1/registrationAuthorityFacade' from module 'stars21_web-stars21-context-root' of application 'stars21_web'. The ejb-ref does not have an ejb-link and the JNDI name of the target bean has not been specified. Attempts to automatically link the ejb-ref to its target bean failed because no EJBs in the application were found to implement the 'sg.com.stee.stars21.common.facade.RegistrationAuthorityFacade' interface. Please link or map this ejb-ref to its target EJB and ensure the interfaces declared in the ejb-ref are correct.
    [05:23:49 PM] See server logs or server console for more details.
    oracle.jdeveloper.deploy.DeployException: oracle.jdeveloper.deploy.DeployException: oracle.jdeveloper.deploy.DeployException: Deployment Failed
    oracle.jdeveloper.deploy.DeployException: oracle.jdeveloper.deploy.DeployException: oracle.jdeveloper.deploy.DeployException: Deployment Failed
    [05:23:49 PM] #### Deployment incomplete. ####
         at oracle.jdevimpl.deploy.common.Jsr88RemoteDeployer.doDeploymentAction(Jsr88RemoteDeployer.java:341)
         at oracle.jdevimpl.deploy.common.Jsr88RemoteDeployer.deployImpl(Jsr88RemoteDeployer.java:235)
         at oracle.jdeveloper.deploy.common.AbstractDeployer.deploy(AbstractDeployer.java:94)
         at oracle.jdevimpl.deploy.fwk.WrappedDeployer.deployImpl(WrappedDeployer.java:39)
         at oracle.jdeveloper.deploy.common.AbstractDeployer.deploy(AbstractDeployer.java:94)
         at oracle.jdeveloper.deploy.common.BatchDeployer.deployImpl(BatchDeployer.java:82)
         at oracle.jdeveloper.deploy.common.AbstractDeployer.deploy(AbstractDeployer.java:94)
         at oracle.jdevimpl.deploy.fwk.WrappedDeployer.deployImpl(WrappedDeployer.java:39)
         at oracle.jdeveloper.deploy.common.AbstractDeployer.deploy(AbstractDeployer.java:94)
         at oracle.jdevimpl.deploy.fwk.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:442)
         at oracle.jdeveloper.deploy.DeploymentManager.deploy(DeploymentManager.java:209)
         at oracle.jdevimpl.runner.adrs.AdrsStarter$6$1.run(AdrsStarter.java:1469)
    Caused by: oracle.jdeveloper.deploy.DeployException: oracle.jdeveloper.deploy.DeployException: Deployment Failed
         at oracle.jdevimpl.deploy.common.Jsr88DeploymentHelper.redeployApplications(Jsr88DeploymentHelper.java:627)
         at oracle.jdevimpl.deploy.common.Jsr88RemoteDeployer.doDeploymentAction(Jsr88RemoteDeployer.java:315)
         ... 11 more
    Caused by: oracle.jdeveloper.deploy.DeployException: Deployment Failed
         at oracle.jdevimpl.deploy.common.Jsr88DeploymentHelper.redeployApplications(Jsr88DeploymentHelper.java:608)
         ... 12 more
    #### Cannot run application stars21_web due to error deploying to DefaultServer.
    [Application stars21_web stopped and undeployed from Server Instance DefaultServer]

  • 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.

Maybe you are looking for