1

I am trying to insert into a table having 3 columns.The primary key of this table being foreign keys to many table has many one to many and many to many relations.While trying to insert i set all these columns but there were some others set methods which i do not use. When i did em.persist to this class it is throwing nullpointerexception. Any idea why is it doing so? Do i have to set other members of class also?

the entity class is as follows

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package objectRelationalMapping;

import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author jai
 */
@Entity
@Table(name = "entitymain")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Entitymain.findAll", query = "SELECT e FROM Entitymain e"),
    @NamedQuery(name = "Entitymain.findByUuid", query = "SELECT e FROM Entitymain e WHERE e.uuid = :uuid"),
    @NamedQuery(name = "Entitymain.findByEntityname", query = "SELECT e FROM Entitymain e WHERE e.entityname = :entityname")})
public class Entitymain implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "uuid")
    private Integer uuid;


    @Size(max = 100)
    @Column(name = "entityname")
    private String entityname;

    @JoinTable(name = "successor", joinColumns = {
        @JoinColumn(name = "emmo_id", referencedColumnName = "uuid")}, inverseJoinColumns = {
        @JoinColumn(name = "successor_id", referencedColumnName = "uuid")})
    @ManyToMany
    private List<Entitymain> entitymainList;

    @ManyToMany(mappedBy = "entitymainList")
    private List<Entitymain> entitymainList1;


    @JoinTable(name = "predecessor", joinColumns = {
        @JoinColumn(name = "emmo_id", referencedColumnName = "uuid")}, inverseJoinColumns = {
        @JoinColumn(name = "predecessor_id", referencedColumnName = "uuid")})
    @ManyToMany
    private List<Entitymain> entitymainList2;

    @ManyToMany(mappedBy = "entitymainList2")
    private List<Entitymain> entitymainList3;


    @JoinTable(name = "operation", joinColumns = {
        @JoinColumn(name = "emmo_id", referencedColumnName = "uuid")}, inverseJoinColumns = {
        @JoinColumn(name = "operator_id", referencedColumnName = "operator_id")})
    @ManyToMany
    private List<Operators> operatorsList;


    @JoinTable(name = "nodes", joinColumns = {
        @JoinColumn(name = "emmo_id", referencedColumnName = "uuid")}, inverseJoinColumns = {
        @JoinColumn(name = "node_id", referencedColumnName = "uuid")})
    @ManyToMany
    private List<Entitymain> entitymainList4;


    @ManyToMany(mappedBy = "entitymainList4")
    private List<Entitymain> entitymainList5;


    @JoinTable(name = "entitytype", joinColumns = {
        @JoinColumn(name = "uuid", referencedColumnName = "uuid")}, inverseJoinColumns = {
        @JoinColumn(name = "oid", referencedColumnName = "uuid")})
    @ManyToMany
    private List<Entitymain> entitymainList6;


    @ManyToMany(mappedBy = "entitymainList6")
    private List<Entitymain> entitymainList7;


    @JoinColumn(name = "entity_kid", referencedColumnName = "entity_kid")
    @ManyToOne
    private EntityKind entityKid;


    @OneToOne(cascade = CascadeType.ALL, mappedBy = "entitymain")
    private Association association;


    @OneToMany(cascade = CascadeType.ALL, mappedBy = "targetId")
    private List<Association> associationList;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "sourceId")
    private List<Association> associationList1;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "entitymain")
    private List<Features> featuresList;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "lmpId")
    private List<Connector> connectorList;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "entitymain")
    private List<Attributes> attributesList;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "entitymain1")
    private List<Attributes> attributesList1;

    public Entitymain() {
    }

    public Entitymain(Integer uuid) {
        this.uuid = uuid;
    }

    public Integer getUuid() {
        return uuid;
    }

    public void setUuid(Integer uuid) {
        this.uuid = uuid;
    }

    public String getEntityname() {
        return entityname;
    }

    public void setEntityname(String entityname) {
        this.entityname = entityname;
    }

    @XmlTransient
    public List<Entitymain> getEntitymainList() {
        return entitymainList;
    }

    public void setEntitymainList(List<Entitymain> entitymainList) {
        this.entitymainList = entitymainList;
    }

    @XmlTransient
    public List<Entitymain> getEntitymainList1() {
        return entitymainList1;
    }

    public void setEntitymainList1(List<Entitymain> entitymainList1) {
        this.entitymainList1 = entitymainList1;
    }

    @XmlTransient
    public List<Entitymain> getEntitymainList2() {
        return entitymainList2;
    }

    public void setEntitymainList2(List<Entitymain> entitymainList2) {
        this.entitymainList2 = entitymainList2;
    }

    @XmlTransient
    public List<Entitymain> getEntitymainList3() {
        return entitymainList3;
    }

    public void setEntitymainList3(List<Entitymain> entitymainList3) {
        this.entitymainList3 = entitymainList3;
    }

    @XmlTransient
    public List<Operators> getOperatorsList() {
        return operatorsList;
    }

    public void setOperatorsList(List<Operators> operatorsList) {
        this.operatorsList = operatorsList;
    }

    @XmlTransient
    public List<Entitymain> getEntitymainList4() {
        return entitymainList4;
    }

    public void setEntitymainList4(List<Entitymain> entitymainList4) {
        this.entitymainList4 = entitymainList4;
    }

    @XmlTransient
    public List<Entitymain> getEntitymainList5() {
        return entitymainList5;
    }

    public void setEntitymainList5(List<Entitymain> entitymainList5) {
        this.entitymainList5 = entitymainList5;
    }

    @XmlTransient
    public List<Entitymain> getEntitymainList6() {
        return entitymainList6;
    }

    public void setEntitymainList6(List<Entitymain> entitymainList6) {
        this.entitymainList6 = entitymainList6;
    }

    @XmlTransient
    public List<Entitymain> getEntitymainList7() {
        return entitymainList7;
    }

    public void setEntitymainList7(List<Entitymain> entitymainList7) {
        this.entitymainList7 = entitymainList7;
    }

    public EntityKind getEntityKid() {
        return entityKid;
    }

    public void setEntityKid(EntityKind entityKid) {
        this.entityKid = entityKid;
    }

    public Association getAssociation() {
        return association;
    }

    public void setAssociation(Association association) {
        this.association = association;
    }

    @XmlTransient
    public List<Association> getAssociationList() {
        return associationList;
    }

    public void setAssociationList(List<Association> associationList) {
        this.associationList = associationList;
    }

    @XmlTransient
    public List<Association> getAssociationList1() {
        return associationList1;
    }

    public void setAssociationList1(List<Association> associationList1) {
        this.associationList1 = associationList1;
    }

    @XmlTransient
    public List<Features> getFeaturesList() {
        return featuresList;
    }

    public void setFeaturesList(List<Features> featuresList) {
        this.featuresList = featuresList;
    }

    @XmlTransient
    public List<Connector> getConnectorList() {
        return connectorList;
    }

    public void setConnectorList(List<Connector> connectorList) {
        this.connectorList = connectorList;
    }

    @XmlTransient
    public List<Attributes> getAttributesList() {
        return attributesList;
    }

    public void setAttributesList(List<Attributes> attributesList) {
        this.attributesList = attributesList;
    }

    @XmlTransient
    public List<Attributes> getAttributesList1() {
        return attributesList1;
    }

    public void setAttributesList1(List<Attributes> attributesList1) {
        this.attributesList1 = attributesList1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (uuid != null ? uuid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Entitymain)) {
            return false;
        }
        Entitymain other = (Entitymain) object;
        if ((this.uuid == null && other.uuid != null) || (this.uuid != null && !this.uuid.equals(other.uuid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "objectRelationalMapping.Entitymain[ uuid=" + uuid + " ]";
    }

}

for persisting i am doing this in a function.I have created objects for each and there is no compilation error.Also these variables are getting set .

public class MapOntology {

@PersistenceContext(unitName = "mmdb-ejbPU")
private EntityManager em;

Entitymain entitymain = new Entitymain();
EntityKind entitykind = new EntityKind();
EntityKindFacade ekf;

public void persistOntology(EntityOntologyBeans objOntology) {

    //Integer uuid = new Integer(objEntityOntologyBeans.getUuid().getUuid());                
   // entitykind.setEntityKid(ekf.getkindId(objOntology.getEntitykind()));
   // em.flush();
    entitymain.setUuid(1);
    entitykind.setEntityKid(2);

    entitymain.setEntityname(objOntology.getEntityname());
    entitymain.setEntityKid(entitykind);

   em.getTransaction().begin();

    em.persist(entitymain);
    em.getTransaction().commit();

}

it is giving null pointer exception at the last line of the above function. Please help

Stack trace is as follows

WARNING: EJB5184:A system exception occurred during an invocation on EJB InsertTransaction, method: public java.lang.String transactions.InsertTransaction.insertOntology()
WARNING: javax.ejb.EJBException
    at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5215)
    at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5113)
    at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4901)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2045)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1994)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
    at $Proxy445.insertOntology(Unknown Source)
    at transactions.__EJB31_Generated__InsertTransaction__Intf____Bean__.insertOntology(Unknown Source)
    at servlet.NewServlet.processRequest(NewServlet.java:63)
    at servlet.NewServlet.doPost(NewServlet.java:101)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
    at mappingProcess.MapOntology.persistOntology(MapOntology.java:69)
    at transactions.InsertTransaction.insertOntology(InsertTransaction.java:49)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
    at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
    at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5388)
    at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144)
    at sun.reflect.GeneratedMethodAccessor159.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
    at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:370)
    at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5360)
    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5348)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:214)
    ... 31 more

SEVERE: javax.ejb.EJBException
    at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5215)
    at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5113)
    at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4901)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2045)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1994)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
    at $Proxy445.insertOntology(Unknown Source)
    at transactions.__EJB31_Generated__InsertTransaction__Intf____Bean__.insertOntology(Unknown Source)
    at servlet.NewServlet.processRequest(NewServlet.java:63)
    at servlet.NewServlet.doPost(NewServlet.java:101)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
    at mappingProcess.MapOntology.persistOntology(MapOntology.java:69)
    at transactions.InsertTransaction.insertOntology(InsertTransaction.java:49)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
    at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
    at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5388)
    at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144)
    at sun.reflect.GeneratedMethodAccessor159.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
    at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:370)
    at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5360)
    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5348)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:214)
    ... 31 more

SEVERE:     at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5215)
SEVERE:     at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5113)
SEVERE:     at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4901)
SEVERE:     at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2045)
SEVERE:     at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1994)
SEVERE:     at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)
SEVERE:     at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
SEVERE:     at $Proxy445.insertOntology(Unknown Source)
SEVERE:     at transactions.__EJB31_Generated__InsertTransaction__Intf____Bean__.insertOntology(Unknown Source)
SEVERE:     at servlet.NewServlet.processRequest(NewServlet.java:63)
SEVERE:     at servlet.NewServlet.doPost(NewServlet.java:101)
SEVERE:     at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
SEVERE:     at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
SEVERE:     at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
SEVERE:     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
SEVERE:     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
SEVERE:     at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
SEVERE:     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
SEVERE:     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
SEVERE:     at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
SEVERE:     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
SEVERE:     at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
SEVERE:     at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
SEVERE:     at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
SEVERE:     at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
SEVERE:     at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
SEVERE:     at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
SEVERE:     at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
SEVERE:     at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
SEVERE:     at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
SEVERE:     at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
SEVERE:     at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
SEVERE:     at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
SEVERE:     at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
SEVERE:     at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
SEVERE:     at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
SEVERE:     at java.lang.Thread.run(Thread.java:722)
SEVERE: Caused by: java.lang.NullPointerException
SEVERE:     at mappingProcess.MapOntology.persistOntology(MapOntology.java:69)
SEVERE:     at transactions.InsertTransaction.insertOntology(InsertTransaction.java:49)
SEVERE:     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
SEVERE:     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
SEVERE:     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
SEVERE:     at java.lang.reflect.Method.invoke(Method.java:601)
SEVERE:     at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
SEVERE:     at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
SEVERE:     at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5388)
SEVERE:     at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
SEVERE:     at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
SEVERE:     at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
SEVERE:     at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
SEVERE:     at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144)
SEVERE:     at sun.reflect.GeneratedMethodAccessor159.invoke(Unknown Source)
SEVERE:     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
SEVERE:     at java.lang.reflect.Method.invoke(Method.java:601)
SEVERE:     at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
SEVERE:     at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
SEVERE:     at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:370)
SEVERE:     at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5360)
SEVERE:     at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5348)
SEVERE:     at com.sun.ejb.containers.EJB

LocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:214) SEVERE: ... 31 more

jairaj
  • 1,789
  • 5
  • 19
  • 32
  • 2
    Please post stack trace. – AlexR Jun 13 '12 at 07:42
  • 1
    The EntityManager em is null. This is causing the NPE – perissf Jun 13 '12 at 08:00
  • @perissf : what to do for it?? i have done it in the same way before for some other table and it worked. here the class is a bit complex with many setter methods. – jairaj Jun 13 '12 at 08:28
  • First, you can have a look to the existing questions related to NPE and EntityManager. You can also keep in front of you some Java EE 6 tutorial (the one by Oracle is great: http://docs.oracle.com/javaee/6/tutorial/doc/ ). If you still need help, post the code of the class containing func() – perissf Jun 13 '12 at 08:32
  • @perissf : public class MapOntology{ @PersistenceContext(unitName = "mmdb-ejbPU") private EntityManager em; Entitymain entitymain = new Entitymain(); EntityKind entitykind = new EntityKind(); EntityKindFacade ekf public void persistOntology(EntityOntologyBeans objOntology) { entitymain.setUuid(1); entitykind.setEntityKid(2); entitymain.setEntityname(objOntology.getEntityname()); entitymain.setEntityKid(entitykind); em.getTransaction().begin(); } – jairaj Jun 13 '12 at 08:38
  • It's not yet clear if you still have the NPE or if you have another exception, and which line is throwing it. Update your question accordingly. Have you studied the tutorial that I have linked? I also suggest to use container managed transactions unless you have a reason for doing differently. In this case, you don't need em.getTransaction() – perissf Jun 13 '12 at 10:58
  • @perissf : The error was NPE and it got solved.It was null giving NPE when i called persist method of it. – jairaj Jun 14 '12 at 08:24
  • Excellent. I am undeleting the answer I gave yesterday. You can accept the one that helped (most) to solve the issue. – perissf Jun 14 '12 at 09:30

4 Answers4

1

In general you have to call all setters of non nullable columns in your database. If a column can be null you don't need to set a value for it. This is like expected. If you would have missed to call a setter of a non nullable database field you would see a different exception. The NPE is probably thrown because of a bug in your code.

Kai
  • 38,985
  • 14
  • 88
  • 103
  • actually the columns in the entitymain table are only three and i am setting them. the other members mainly list are created because they have a foreign key of the primary key of this table. do i need to set them also before persisting?? – jairaj Jun 13 '12 at 08:21
  • @jairaj Have you tried setting empty Lists for the Lists? If they are null this might be causeing the NPE. Please post the full stacktrace. – Kai Jun 13 '12 at 08:57
  • yes i tried but then nothing changed. the error for NPE is that the entitymanager em is null. i have checked by equaling it with null and it is null.any idea how to initialise or set it to not null? – jairaj Jun 13 '12 at 09:03
1

You can only use injection on managed classes, such as SessionBeans. You need to initialize your EntityManager by either using Persistence, or a JNDI lookup, or use a SessionBean.

James
  • 17,965
  • 11
  • 91
  • 146
0

Your are injecting your EntityManager using @PersistenceContext annotation. This operation can only be done if your client class MapOntology is itself managed by the container.

Annotating it as @Stateless should solve the problem.

See this answer for further reference.

Community
  • 1
  • 1
perissf
  • 15,979
  • 14
  • 80
  • 117
0

I finally found it out. the reason for NEP was entitymanager em not being initialised.To initialize it you have to write @EJB annotation before declaring the class object containing the entitymanager.It stops giving the NEP error and also it is not required to set all the member attributes of the entity classes just make sure that the columns set as not null are given values(proper).Then you can persist them and insert into database.

jairaj
  • 1,789
  • 5
  • 19
  • 32