6 Replies Latest reply on May 28, 2015 1:38 PM by Emmanuel Silva

    OrientDB JCA Resource Injection

    shelltux Newbie

      Hi everybody,

       

      because it is my first post here I will give a short introduction to myself :-)

      My name is Markus and I am truly new to J2EE programming and WildFly. I got some experience with plain and good old java as well as with Spring.

       

      I'm trying to get a working OrientDB-JCA-Connector, downloaded from: Orient - OPS4J Orient - OPS4J Wiki

      I deployed the adapter as stated in the "Installation on WildFly" chapter.

       

      What I am trying is that a simple Primefaces-JSF with a backing bean has en EJB injected and that EJB has a @Resource-lookup for the OrientDB-JCA.

       

      My backing bean looks like this

      @ManagedBean
      @RequestScoped
      public class TestBean {
        protected Logger log = Logger.getLogger(this.getClass());
      
        @EJB
        private TestEJB ejb;
        /**
        * 
        */
        public TestBean() {
        log.info("TestBean constructed");
        }
      
        public String getSomeString() { return(ejb.getSomeString()); }
      
      
      }
      

       

      The TestEJB looks like:

      @Named
      @Stateless
      public class TestEJB {
        protected Logger log = Logger.getLogger(this.getClass());
      
        @Resource(lookup = "java:/orient/ConnectionFactory")
        private OrientDatabaseConnection omc;
      
        private String someString = null;
      
        public TestEJB() {
        log.info("TestEJB constructed");
        this.someString = "Ein Test";
        }
      
        public String getSomeString() { return(this.someString); }
      }
      

       

      The simple injection of the EJB into the backing bean works as desired (if I comment that @Resource-Part everything works fine).

       

      While the Wildfly 8.x server is starting I can the following message

       

      20:52:32,859 INFO  [org.jboss.as.connector.deployment] (MSC service thread 1-9) JBAS010401: Bound JCA ConnectionFactory [java:/orient/ConnectionFactory]
      

       

      For me it looks like that the ConnectionFactory is known be the container.

      If I then open the JSF the following stacktrace occurs:

      Caused by: java.lang.IllegalArgumentException: Can not set org.ops4j.orient.adapter.api.OrientDatabaseConnection field de.verleihmalwas.ejb.orientdb.TestEJB.omc to org.ops4j.orient.adapter.impl.OrientDatabaseConnectionFactoryImpl
        at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:164) [rt.jar:1.7.0_72]
        at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:168) [rt.jar:1.7.0_72]
        at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81) [rt.jar:1.7.0_72]
        at java.lang.reflect.Field.set(Field.java:741) [rt.jar:1.7.0_72]
        at org.jboss.as.ee.component.ManagedReferenceFieldInjectionInterceptorFactory$ManagedReferenceFieldInjectionInterceptor.processInvocation(ManagedReferenceFieldInjectionInterceptorFactory.java:108)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
        at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
        at org.jboss.as.ee.component.AroundConstructInterceptorFactory$1.processInvocation(AroundConstructInterceptorFactory.java:28)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
        at org.jboss.as.weld.injection.WeldInterceptorInjectionInterceptor.processInvocation(WeldInterceptorInjectionInterceptor.java:56) [wildfly-weld-8.1.0.Final.jar:8.1.0.Final]
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
        at org.jboss.as.weld.ejb.Jsr299BindingsCreateInterceptor.processInvocation(Jsr299BindingsCreateInterceptor.java:93) [wildfly-weld-8.1.0.Final.jar:8.1.0.Final]
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
        at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
        at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:273) [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final]
        ... 118 more
      

       

      Does anyone have an idea that I am doing wrong?

       

      Thanks and regards

       

      Markus

        • 1. Re: OrientDB JCA Resource Injection
          Jay SenSharma Master

          Can you try changing the following

           

          @Resource(lookup = "java:/orient/ConnectionFactory") 
          private OrientDatabaseConnection omc; 
          

           

          to

           

          @Resource(lookup = "java:/orient/ConnectionFactory") 
          private OrientDatabaseConnectionFactory ocf;
          

           

          Then later try getting the connection like following:

           

          OrientDatabaseConnection omc =  ocf.createConnection()
          
          • 2. Re: Re: OrientDB JCA Resource Injection
            shelltux Newbie

            Hi Jay,

             

            thanks for your reply.

             

            Now my test-EJB looks like:

             

            @Named
            @Stateless
            public class TestEJB {
              protected Logger log = Logger.getLogger(this.getClass());
            
              @Resource(lookup = "java:/orient/ConnectionFactory")
              private OrientDatabaseConnectionFactory ocf;
            
              private String someString = null;
            
              public TestEJB() {
              log.info("TestEJB constructed");
              this.someString = "Ein Test";
            
              if(ocf == null) { log.info("ocf is null"); }
              }
            
              public String getSomeString() { return(this.someString); }
            }
            

             

            Here are the log(s):

            18:25:58,196 INFO  [de.abc.beans.TestBean] (default task-3) TestBean constructed
            18:25:58,196 INFO  [de.abc.ejb.orientdb.TestEJB$$$view4] (default task-3) TestEJB constructed
            18:25:58,196 INFO  [de.abc.ejb.orientdb.TestEJB$$$view4] (default task-3) ocf is null
            18:25:58,196 INFO  [de.abc.ejb.orientdb.TestEJB] (default task-3) TestEJB constructed
            18:25:58,196 INFO  [de.abc.ejb.orientdb.TestEJB] (default task-3) ocf is null
            .
            .
            .
            Caused by: java.lang.IllegalArgumentException: Can not set org.ops4j.orient.adapter.api.OrientDatabaseConnectionFactory field de.abc.ejb.orientdb.TestEJB.ocf to org.ops4j.orient.adapter.impl.OrientDatabaseConnectionFactoryImpl
              at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:164) [rt.jar:1.7.0_72]
              at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:168) [rt.jar:1.7.0_72]
              at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81) [rt.jar:1.7.0_72]
              at java.lang.reflect.Field.set(Field.java:741) [rt.jar:1.7.0_72]
              at org.jboss.as.ee.component.ManagedReferenceFieldInjectionInterceptorFactory$ManagedReferenceFieldInjectionInterceptor.processInvocation(ManagedReferenceFieldInjectionInterceptorFactory.java:108)
              at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
              at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
              at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
              at org.jboss.as.ee.component.AroundConstructInterceptorFactory$1.processInvocation(AroundConstructInterceptorFactory.java:28)
              at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
              at org.jboss.as.weld.injection.WeldInterceptorInjectionInterceptor.processInvocation(WeldInterceptorInjectionInterceptor.java:56) [wildfly-weld-8.1.0.Final.jar:8.1.0.Final]
              at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
              at org.jboss.as.weld.ejb.Jsr299BindingsCreateInterceptor.processInvocation(Jsr299BindingsCreateInterceptor.java:93) [wildfly-weld-8.1.0.Final.jar:8.1.0.Final]
              at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
              at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
              at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
              at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:273) [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final]
              ... 118 more
            

             

            Regards,

             

            Markus

            • 3. Re: OrientDB JCA Resource Injection
              Jesper Pedersen Master

              You likely need to replace "private OrientDatabaseConnection" with "private OrientDatabaseConnectionFactory"

              • 4. Re: OrientDB JCA Resource Injection
                shelltux Newbie

                Hi Jesper,

                 

                thanks for your reply but this is what I've done. Take a look at my last post.

                 

                Regards

                 

                Markus

                • 5. Re: OrientDB JCA Resource Injection
                  Emmanuel Silva Newbie

                  Hi sheltux!

                   

                  I'm having the same exception message, did you solve it?


                  java.lang.IllegalArgumentException: Can not set org.ops4j.orient.adapter.api.OrientDatabaseConnection field de.verleihmalwas.ejb.orientdb.TestEJB.omc to org.ops4j.orient.adapter.impl.OrientDatabaseConnectionFactoryImpl   - See more at: https://developer.jboss.org/thread/250456#sthash.wzZhqGeF.dpuf

                   

                  Thank's a lot!

                  Regards


                  Emmanuel Silva

                  • 6. Re: OrientDB JCA Resource Injection
                    Emmanuel Silva Newbie

                    I forgot to remove the orientdb-rar-api from application classpath because the libraries are packaged into JCA Connector and now works fine!