java ee - nullpointerexception when persisting bean -


i use wildfly 8.2, javaee 7 , h2 database. when try persist or merge entity, got npe. below classes. know why?

@entity public class patient implements serializable {      @id     @generatedvalue(strategy = generationtype.auto)     private long id;      private string firstname;     private string lastname;     private date dob;  //getters/setters here } 

my ejb service. findall() works fine.

@stateless public class patientservice {      @persistencecontext(unitname="patient-pu")     private entitymanager em;      public list<patient> findall() {         criteriaquery<patient> cq = em.getcriteriabuilder().createquery(patient.class);         cq.select(cq.from(patient.class));         return em.createquery(cq).getresultlist();     }      public void saveorpersist(patient entity) {         if (entity.getid() > 0) {             em.merge(entity);         } else {             em.persist(entity);         }     }  } 

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="patient-pu" transaction-type="jta">     <jta-data-source>java:jboss/h2</jta-data-source>     <class>com.example.backend.patient</class>   </persistence-unit> </persistence> 

my ui. use vaadin framework

@override     protected void init(vaadinrequest vaadinrequest) {          //create new record         patient patient = new patient();         patient.setfirstname("john");         patient.setlastname("doe");         patient.setdob(new date());         patientservice.saveorpersist(patient);       }  

here's errors i've got

10:02:05,549 error [org.jboss.as.ejb3.invocation] (default task-6) jbas014134: ejb invocation failed on component patientservice method public void com.example.backend.patientservice.saveorpersist(com.example.backend.patient): javax.ejb.ejbexception: java.lang.nullpointerexception     @ org.jboss.as.ejb3.tx.cmttxinterceptor.handleexceptioninourtx(cmttxinterceptor.java:190) [wildfly-ejb3-8.2.0.final.jar:8.2.0.final]     @ org.jboss.as.ejb3.tx.cmttxinterceptor.invokeinourtx(cmttxinterceptor.java:275) [wildfly-ejb3-8.2.0.final.jar:8.2.0.final]     @ org.jboss.as.ejb3.tx.cmttxinterceptor.required(cmttxinterceptor.java:340) [wildfly-ejb3-8.2.0.final.jar:8.2.0.final]     @ org.jboss.as.ejb3.tx.cmttxinterceptor.processinvocation(cmttxinterceptor.java:239) [wildfly-ejb3-8.2.0.final.jar:8.2.0.final]     @ org.jboss.invocation.interceptorcontext.proceed(interceptorcontext.java:309)     @ org.jboss.as.ejb3.component.interceptors.currentinvocationcontextinterceptor.processinvocation(currentinvocationcontextinterceptor.java:41) [wildfly-ejb3-8.2.0.final.jar:8.2.0.final]     @ org.jboss.invocation.interceptorcontext.proceed(interceptorcontext.java:309)     @ org.jboss.as.ejb3.component.invocationmetrics.waittimeinterceptor.processinvocation(waittimeinterceptor.java:43) [wildfly-ejb3-8.2.0.final.jar:8.2.0.final]     @ org.jboss.invocation.interceptorcontext.proceed(interceptorcontext.java:309)     @ org.jboss.as.ejb3.security.securitycontextinterceptor.processinvocation(securitycontextinterceptor.java:95) [wildfly-ejb3-8.2.0.final.jar:8.2.0.final]     @ org.jboss.invocation.interceptorcontext.proceed(interceptorcontext.java:309)     @ org.jboss.as.ejb3.component.interceptors.shutdowninterceptorfactory$1.processinvocation(shutdowninterceptorfactory.java:64) [wildfly-ejb3-8.2.0.final.jar:8.2.0.final]     @ org.jboss.invocation.interceptorcontext.proceed(interceptorcontext.java:309)     @ org.jboss.as.ejb3.component.interceptors.logginginterceptor.processinvocation(logginginterceptor.java:59) [wildfly-ejb3-8.2.0.final.jar:8.2.0.final]     @ org.jboss.invocation.interceptorcontext.proceed(interceptorcontext.java:3 


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -