6 Replies Latest reply on Jan 14, 2013 6:19 AM by Stephen Coy

    JBAS014134: EJB Invocation failed on component Information for method public abstract java.lang.String ejb.InformationRemote.save(entity.Child) throws java.lang.Exception: javax.ejb.EJBException: java.lang.NullPointerException

    JONES GOLD I Newbie

      I am doing  JPA ONE TO ONE REALATION (USING JSF AS CLIENT)

       

      THIS IS MY TABLES

       

       

       

      CREATE TABLE `CHILD` (
      `id` int(11) NOT NULL auto_increment,
      `parentAge` int(11) default NULL,
      `pfirstName` varchar(255) default NULL,
      `plastName` varchar(255) default NULL,
      `cId` int(11) default NULL,
      PRIMARY KEY  (`id`),
      KEY `FKC4AB08AACD2DFD9A` (`cId`),
      CONSTRAINT `FKC4AB08AACD2DFD9A`
      FOREIGN KEY (`cId`) REFERENCES `PARENT` (`id`)
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1

      .

      Table: Child.

      CREATE TABLE `PARENT` (
      `id` int(11) NOT NULL auto_increment,
      `cfirstName` varchar(255) default NULL,
      `childAge` int(11) default NULL,
      `clastName` varchar(255) default NULL,
      PRIMARY KEY  (`id`)
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1

        .

       

      AND THIS MY POJO CLASSES

       

      package entity;

      import java.io.Serializable;

      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.GeneratedValue;
      import javax.persistence.Id;
      import javax.persistence.JoinColumn;
      import javax.persistence.OneToOne;
      import javax.persistence.Table;

      @Entity
      @Table(name="parent")
      public class Parent implements Serializable{
      @Id
      @GeneratedValue
      @Column(name="id")
      private int id;
      @Column(name="cfirstName")
      private String cfirstName;
      @Column(name="clastName")
      private String clastName;
      @Column(name="childAge")
      private int childAge; 

      public int getId() {
      return id;
      }
      public void setId(int id) {
      this.id = id;
      }
      public String getCfirstName() {
      return cfirstName;
      }
      public void setCfirstName(String cfirstName) {
      this.cfirstName = cfirstName;
      }
      public String getClastName() {
      return clastName;
      }
      public void setClastName(String clastName) {
      this.clastName = clastName;
      }
      public int getChildAge() {
      return childAge;
      }
      public void setChildAge(int childAge) {
      this.childAge = childAge;
      }
      }

      <----------------------------------------------------------------------------------------------------------------------------------------->

       

      package entity;

      import java.io.Serializable;

      import javax.persistence.CascadeType;
      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.FetchType;
      import javax.persistence.GeneratedValue;
      import javax.persistence.Id;
      import javax.persistence.JoinColumn;
      import javax.persistence.OneToOne;
      import javax.persistence.Table;

      @Entity
      @Table(name="child")
      public class Child implements Serializable{
      @Id
      @GeneratedValue
      @Column(name="id")
      private int id;
      @Column(name="pfirstName")
      private String pfirstName;
      @Column(name="plastName")
      private String plastName;
      @Column(name="parentAge")
      private int parentAge;
      @OneToOne(cascade=CascadeType.ALL,
      fetch=FetchType.EAGER)
      @JoinColumn(name="cId")
      private Parent parent;

      public int getId() {
      return id;
      }
      public void setId(int id) {
      this.id = id;
      }
      public String getPfirstName() {
      return pfirstName;
      }
      public void setPfirstName(String pfirstName) {
      this.pfirstName = pfirstName;
      }
      public String getPlastName() {
      return plastName;
      }
      public void setPlastName(String plastName) {
      this.plastName = plastName;
      }
      public int getParentAge() {
      return parentAge;
      }
      public void setParentAge(int parentAge) {
      this.parentAge = parentAge;
      }
      public Parent getParent() {
      return parent;
      }
      public void setParent(Parent parent) {
      this.parent = parent;
      }

      }

       

      AND MY EJB CLASSES

       

      package ejb;

       


      import javax.ejb.Remote;
      import javax.ejb.Stateless;
      import javax.transaction.*;

      import entity.*;
      import javax.persistence.EntityManager;
      import javax.persistence.EntityManagerFactory;
      import javax.persistence.EntityTransaction;
      import javax.persistence.Persistence;
      import org.hibernate.ejb.HibernatePersistence;
      import javax.persistence.EntityTransaction;
      /**
      * Session Bean implementation class Information
      */
      @Stateless
      @Remote(InformationRemote.class)
      public class Information implements InformationRemote {

          /**
      * Default constructor.
      */
      public Information() {
      // TODO Auto-generated constructor s
      }

      public String save(Child child) throws Exception
      {
      EntityManagerFactory emf = Persistence.createEntityManagerFactory("JPADB");
      EntityManager em = emf.createEntityManager();

        EntityTransaction entr = em.getTransaction();
        entr.begin();
        em.persist(child);
        entr.commit();



      em.close();

          
      return("sucess");
      }
      }

      PERSISTENCE.XML

       

      <?

      xml version="1.0" encoding="UTF-8"?> <persistence version=

      "2.0"

      xmlns="http://java.sun.com/xml/ns/persistence"

      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

      xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

      <persistence-unit name="JPADB">

      <jta-data-source>java:/MySQLDS</jta-data-source>

      <properties>

      <property name="showSql" value="true"/>

      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />

      </properties>

      </persistence-unit>

      </persistence>

      AND THIS IS JSF2.0 BEAN

      package bean;

      import javax.faces.bean.ManagedBean;

      import javax.naming.Context;

      import javax.naming.NamingException;

       

      import jndi.JNDILookupClass;

       

      import ejb.*;

      import entity.*;

       

      @ManagedBean

      public class InsertBean {

       

             Parent p =new Parent();

             Child c=new Child();

       

             public Parent getP() {

                    return p;

             }

       

             public void setP(Parent p) {

                    this.p = p;

             }

       

       

             public Child getC() {

                    return c;

             }

       

             public void setC(Child c) {

                    this.c = c;

             }

       

             private static InformationRemote doLookup() {

              Context context = null;

              InformationRemote   bean = null;

       

              try {

                  // 1. Obtaining Context

                  context = JNDILookupClass.getInitialContext(); 

                  // 2. Generate JNDI Lookup name

                  String lookupName = getLookupName();

                  // 3. Lookup and cast

                  bean = (InformationRemote) context.lookup(lookupName);

       

              } catch (NamingException e) {

                  e.printStackTrace();

              }

              return bean;

          }

       

       

             private static String getLookupName() {

      /*The app name is the EAR name of the deployed EJB without .ear

      suffix. Since we haven't deployed the application as a .ear, the app

      name for us will be an empty string */

      String appName = "ejb3jpaonetoone";

       

      /* The module name is the JAR name of the deployed EJB without the

      .jar suffix.*/

      String moduleName = "onetoone";

       

      /* AS7 allows each deployment to have an (optional) distinct name.

      This can be an empty string if distinct name is not specified.*/

      String distinctName = "";

       

      // The EJB bean implementation class name

      String beanName = Information.class.getSimpleName();

       

      // Fully qualified remote interface name

      final String interfaceName = InformationRemote.class.getName();

       

      // Create a look up string name

      String name = "ejb:" + appName + "/" + moduleName + "/" +

                            distinctName    + "/" + beanName + "!" + interfaceName;

      return name;

      }

       

             public void save()

             {

                    InformationRemote bean=doLookup();

       

                    c.setParent(p);

                    try

                    {

                    String res=bean.save(c);

                    }

                    catch(Exception e)

                    {

                           System.out.println("this is a exception"+e);

                    }

       

             }

       

      }

      WHEN I RUN MY PROJECT SERVER SHOWING

       

      12:17:01,846 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (http-localhost-127.0.0.1-8080-1) HHH000397: Using ASTQueryTranslatorFactory

      12:17:02,167 ERROR [org.jboss.ejb3.invocation] (http-localhost-127.0.0.1-8080-1) JBAS014134: EJB Invocation failed on component Information for method public abstract java.lang.String ejb.InformationRemote.save(entity.Child) throws java.lang.Exception: javax.ejb.EJBException: java.lang.NullPointerException

                at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:166) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

                at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:230) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

                at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:304) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

                at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:190) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                at org.jboss.as.ejb3.remote.EJBRemoteTransactionPropagatingInterceptor.processInvocation(EJBRemoteTransactionPropagatingInterceptor.java:80) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:32) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

                at org.jboss.as.ejb3.remote.LocalEjbReceiver.processInvocation(LocalEjbReceiver.java:179) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

                at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:179) [jboss-ejb-client-1.0.5.Final.jar:1.0.5.Final]

                at org.jboss.ejb.client.TransactionInterceptor.handleInvocation(TransactionInterceptor.java:43) [jboss-ejb-client-1.0.5.Final.jar:1.0.5.Final]

                at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181) [jboss-ejb-client-1.0.5.Final.jar:1.0.5.Final]

                at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:128) [jboss-ejb-client-1.0.5.Final.jar:1.0.5.Final]

                at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181) [jboss-ejb-client-1.0.5.Final.jar:1.0.5.Final]

                at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136) [jboss-ejb-client-1.0.5.Final.jar:1.0.5.Final]

                at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121) [jboss-ejb-client-1.0.5.Final.jar:1.0.5.Final]

                at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104) [jboss-ejb-client-1.0.5.Final.jar:1.0.5.Final]

                at $Proxy23.save(Unknown Source)          at bean.InsertBean.save(InsertBean.java:86)

                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_27]

                at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.6.0_27]

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.6.0_27]

                at java.lang.reflect.Method.invoke(Unknown Source) [rt.jar:1.6.0_27]

                at org.apache.el.parser.AstValue.invoke(AstValue.java:262)

                at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)

                at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)

                at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)

                at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)

                at javax.faces.component.UICommand.broadcast(UICommand.java:315)

                at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)

                at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)

                at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)

                at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)

                at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)

                at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)

                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)

                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)

                at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)

                at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)

                at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]

                at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)

                at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)

                at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

                at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

                at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)

                at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)

                at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)

                at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)

                at java.lang.Thread.run(Unknown Source) [rt.jar:1.6.0_27]

      Caused by: java.lang.NullPointerException

                at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.getStatus(JtaStatusHelper.java:73) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]

                at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.isActive(JtaStatusHelper.java:115) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]

                at org.hibernate.engine.transaction.internal.jta.CMTTransaction.join(CMTTransaction.java:149) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]

                at org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:1207) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]

                at org.hibernate.ejb.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:176) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]

                at org.hibernate.ejb.EntityManagerImpl.<init>(EntityManagerImpl.java:89) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]

                at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:125) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]

                at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:120) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]

                at ejb.Information.save(Information.java:33) [onetoone.jar:]

                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_27]

                at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.6.0_27]

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.6.0_27]

                at java.lang.reflect.Method.invoke(Unknown Source) [rt.jar:1.6.0_27]

                at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory$ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptorFactory.java:72) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:36) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:228) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

                ... 58 more

       

       

      12:17:02,242 INFO  [stdout] (http-localhost-127.0.0.1-8080-1) comingthis is a exceptionjavax.ejb.EJBException: java.lang.NullPointerException