I have also seen that here also we are autowiring. But this throws no exception. Why?
And even I have tried autowiring other DAOs in multiple files and use them. That also results in no Exception.
I think this has to do with the classes being in different packages. Try moving the smart classes to the previous package.
I tried with autowiring the DAOs in other packages too like UserCredentialsDAO. Still no NullPointerException
UserCredentialsDAO is in org.openmrs.module.oauth2.api.* and Smart classes in org.openmrs.module.smart.*
Yeah UserCredentialsDAO is in same package as the ClientsDAO. So if it has something with different packages then this was all in all a same case.
Let me pull your code and see
Sure. You think this fix is fine? I mean everything seems to work fine after this fix.
In your code SmartClasses are under âoauth2.apiâ and not âsmartâ https://github.com/PKatGITHUB/openmrs-module-oauth2/tree/gsoc-18/api/src/main/java/org/openmrs/module
Where is the code giving you the error?
@pkatopenmrs I saw your code, what you didnât specify earlier was that NullPointerException was thrown on Hibernate saveOrUpdate() methods. I thought you were talking about bean errors
They are under oauth2.api.smart right?
Yeah⊠the hibernate methods.
You should have mentioned that earlier. ClientDAO autowiring works well. Whatâs giving the NullPointerException is session.getCurrentSession()
Is this because these methods are getting null parameters? If yes then isnât it the same problem of null beans?
âsessionFactoryâ under property target of Transaction manager is referring to HibernateOAuth2DAO
and you are using the same sessionFactory here(https://github.com/PKatGITHUB/openmrs-module-oauth2/blob/07627d8f4b270b23016b4652a2b28e149ef40683/api/src/main/java/org/openmrs/module/oauth2/api/smart/db/hibernate/HibernateSmartDAO.java#L34).
Thatâs why sessionFactory.getCurrentSession() is not working in HibernateOAuth2DAO
So when you explicitly override the default configuration of âtargetâ in transactionManager, that solves the error as it keeps from nulling the session.
It was always a problem of ill-defined HibernateConfiguration and nothing concerning to Autowiring
Yep i got you. But still
this sessionFactory is explicitly defined for the DAO object âdaoâ used in Oauth2ServiceImpl. All the other sessionFactory are autowired.
As you see here :
the sessionFactory is autowired. So this : https://github.com/PKatGITHUB/openmrs-module-oauth2/blob/07627d8f4b270b23016b4652a2b28e149ef40683/api/src/main/java/org/openmrs/module/oauth2/api/smart/db/hibernate/HibernateSmartDAO.java#L34 sessionFactory is different from this : https://github.com/PKatGITHUB/openmrs-module-oauth2/blob/07627d8f4b270b23016b4652a2b28e149ef40683/api/src/main/java/org/openmrs/module/oauth2/api/db/hibernate/HibernateOauth2DAO.java#L33 one right??
Exactly what I am saying. sessionFactory works that way. See this (https://github.com/PKatGITHUB/openmrs-module-oauth2/blob/07627d8f4b270b23016b4652a2b28e149ef40683/api/src/main/resources/moduleApplicationContext.xml#L10). This is Context.getService() definitions.
Now, if you change this to âdaoâ instead of "clientDAO"youâll get the same error as before. This was the error all along as Context.getService() definition were being ambiguous with @Autowire of sessionFactory that we use throughout
You canât understand what I am saying? Remove these lines from the configuration XML. Now, youâll see that clientRegistrationService tests run fine and smartManagementService tests fail giving NullPointerException