Ich benutze Facade-Muster für den Zugriff von Datenbank-Entities. Ich habe einen Wrapper geschrieben, um auf das Facade EJB wie unten zuzugreifen. Wie ich aus der Ausnahme verstehe, scheint es, als ob die EJB nicht initialisiert wurde. Nach dem Lesen über die Ausnahme in Foren, habe ich verstanden, dass es gelöst werden sollte @ PostConstruct Notation, aber immer noch keine Hilfe. Kann ich es falsch verwenden, werden alle Hinweise sehrZugriff EJB von normaler Klasse
public class PatientSearchHelper {
@EJB
private PatientFacade patientFacade;
private final Patient patient;
private ResponseHeader respHeader;
private SearchResponse searchResponse;
private List<Patient> resultSet;
public PatientSearchHelper (Patient patient) {
this.patient = patient;
}
@PostConstruct
public void initialize() {
this.respHeader = new ResponseHeader();
this.searchResponse = new SearchResponse();
}
public SearchResponse getById() {
System.out.println("Patient Id: " + patient.getPatientid());
//patientFacade = (PatientFacade) new InitialContext().lookup("java:global/Aarogayam2/PatientFacade!common.facades.PatientFacade");
resultSet = patientFacade.findById(patient.getPatientid());
if (resultSet.size() > 0) {
formatFoundResponse();
} else {
formatNotFoundResponse();
}
return searchResponse;
}
private void formatFoundResponse() {
searchResponse.setPayload(resultSet);
respHeader.setSuccess(true);
searchResponse.setHeader(respHeader);
}
private void formatNotFoundResponse() {
respHeader.setSuccess(false);
respHeader.setMessage("No Patient found");
searchResponse.setHeader(respHeader);
searchResponse.setPayload(null);
}
}
geschätzt werden jedoch ich die Ausnahme erhalten, wenn es wie unten
PatientSearchHelper searchHelper = new PatientSearchHelper(patient);
searchHelper.initialize();
return searchHelper.getById();
Exception
SEVERE: java.lang.NullPointerException
at common.helpers.PatientSearchHelper.getById(PatientSearchHelper.java:48)
at common.services.PatientService.getById(PatientService.java:57)
at common.services.PatientService$Proxy$_$$_WeldSubclass.getById(Unknown Source)
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:606)
Danke IndoKnight !! PatientSearchHelper statuslos machen löste mein Problem. –