GSoC 2018 - OAuth Module Enhancements And SMART Apps Support Project

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. :confused:

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. :confused:

Let me pull your code and see

Sure. You think this fix is fine? I mean everything seems to work fine after this fix. :slight_smile:

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. :confused:

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?

No. Look at https://github.com/PKatGITHUB/openmrs-module-oauth2/blob/07627d8f4b270b23016b4652a2b28e149ef40683/api/src/main/resources/moduleApplicationContext.xml#L24.

“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