I’m using OpenMRS 1.11.4 and Reference Application 2.3.1 (with bundled modules) in my development environment.
I’m developing a custom module containing some custom API code (Entities, Services and DAO implementation).
Now, I’ve written REST resources for the entities created above. Let us consider one of the entities InformationRequest and I’ve implemented InformationRequestResource1_11 as you can find in the following attachment:
Now when I try to create InformationRequest by POST invocation of the above REST implementaiton, I get the following exception in the logs:
Also tried it using jQuery AJAX from one of the reference application pages but still getting the same exception.
The only thing that changes in the error log is “Current user: Username of logged-in User” instead of “Current user: Guest (Not logged in)”.
On running the application with debug log level, I found this:
... INFO - LoggingAdvice.invoke(115) |2017-01-17 18:22:05,227| In method InformationSharingService.saveInformationRequest. Arguments: InformationRequest=InformationRequest[hashCode=2fe57f6e,uuid=6a7dcb72-2edd-4632-ade9-dbd4ef1f9eb7], DEBUG - AuditableInterceptor.setCreatorAndDateCreatedIfNull(107) |2017-01-17 18:22:05,232| Setting creator and dateCreated on InformationRequest[hashCode=2fe57f6e,uuid=6a7dcb72-2edd-4632-ade9-dbd4ef1f9eb7] ERROR - LoggingAdvice.invoke(135) |2017-01-17 18:22:05,234| An error occurred while executing this method. Current user: email@example.com Error message: null java.lang.NullPointerException at org.openmrs.event.api.db.hibernate.HibernateEventInterceptor.onSave(HibernateEventInterceptor.java:72) ...
Does the exception have anything to do with inserting audit info??
Which version of the module are you running? I highly suspect inserts is what is null on line 72 above, which only happens if there is no transaction that was started which occurs when you don’t have transactions configured properly. You might want to share your code where you setup transactions to see if they are configured well.
Is the resource you are trying to get in core or a module? If it’s in a module you might confirm the transaction configurations on the service methods to ensure that they are correct. If it’s in core what domain object does your resource return.