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:
Does it have anything to do with? Current user: Guest (Not logged in)
Are you able to reproduce it if you do not run in a development or debug environment?
@dkayiwa, I get the same error “Current user: Guest (Not logged in)” even if I use the application by logging-in as Super User or some other user with Organizational roles.
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)”.
Sadly I won’t be able to do that @dkayiwa as I’ve some important custom logic sitting in my referenceapplication module without which I won’t be able to run the application.
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: doctor@demo.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.
@wyclif, do you mean to say the spring and hibernate configurations??
Also, as you said there seems to be a transaction related issue. The REST response for the POST request is a JSON of the resource object but I don’t find any record created in database.
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.
It’s a module @wyclif and the domain object is also a custom entity.
I’ve 1 service class holding all the methods which in tern invoke the HibernateDAO methods. What should be standard transaction configurations for the service??
Are you suggesting that I should mark service methods as @Transactional??