1

我正在尝试插入一个有 3 列的表。这个表的主键是许多表的外键,有很多一对多和多对多的关系。在尝试插入时,我设置了所有这些列,但还有一些其他的设置我不使用的方法。当我对这个类执行 em.persist 时,它会抛出 nullpointerexception。知道为什么要这样做吗?我还必须设置其他班级成员吗?

实体类如下

/*
 * 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 + " ]";
    }

}

为了持久化,我在一个函数中执行此操作。我为每个对象创建了对象,并且没有编译错误。这些变量也正在设置中。

公共类 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();

}

它在上述函数的最后一行给出空指针异常。请帮忙

堆栈跟踪如下

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) 严重:... 31 更多

4

4 回答 4

1

通常,您必须调用数据库中所有不可为空的列的设置器。如果一列可以为空,则无需为其设置值。这和预期的一样。如果您错过了调用不可为空的数据库字段的设置器,您会看到不同的异常。NPE 可能由于您的代码中的错误而被抛出。

于 2012-06-13T07:56:01.400 回答
1

您只能在托管类上使用注入,例如 SessionBeans。您需要使用 Persistence、JNDI 查找或使用 SessionBean 来初始化 EntityManager。

于 2012-06-13T14:08:27.433 回答
0

您正在使用@PersistenceContext注释注入您的 EntityManager。只有当您的客户端类MapOntology本身由容器管理时,才能执行此操作。

注释它@Stateless应该可以解决问题。

请参阅此答案以获取更多参考。

于 2012-06-13T08:57:52.360 回答
0

我终于发现了。NEP 的原因是 entitymanager em 没有被初始化。要初始化它,您必须在声明包含 entitymanager 的类对象之前编写 @EJB 注释。它会停止给出 NEP 错误,并且不需要设置所有成员属性实体类只需确保设置为非空的列被赋予值(正确)。然后您可以将它们持久化并插入到数据库中。

于 2012-06-13T20:03:08.450 回答