问题
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
回答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.
回答2:
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.
回答3:
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.
回答4:
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.
来源:https://stackoverflow.com/questions/11010224/is-it-necessary-to-set-all-the-fields-of-the-entity-classes-when-using-jpa-to-pe