GSoC 2018 - OAuth Module Enhancements And SMART Apps Support Project

Tags: #<Tag:0x00007f88c943ab30>

(Prabodh Kotasthane) #21

I have also seen that here also we are autowiring. But this throws no exception. Why?

(Prabodh Kotasthane) #22

And even I have tried autowiring other DAOs in multiple files and use them. That also results in no Exception. :confused:

(Sanatt Abrol) #23

I think this has to do with the classes being in different packages. Try moving the smart classes to the previous package.

(Prabodh Kotasthane) #24

I tried with autowiring the DAOs in other packages too like UserCredentialsDAO. Still no NullPointerException

(Sanatt Abrol) #25

UserCredentialsDAO is in org.openmrs.module.oauth2.api.* and Smart classes in*

(Prabodh Kotasthane) #26

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:

(Sanatt Abrol) #27

Let me pull your code and see

(Prabodh Kotasthane) #28

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

(Sanatt Abrol) #29

In your code SmartClasses are under “oauth2.api” and not “smart”

Where is the code giving you the error?

(Sanatt Abrol) #30

@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

(Prabodh Kotasthane) #31

They are under right?

(Prabodh Kotasthane) #32

Yeah… the hibernate methods. :confused:

(Sanatt Abrol) #33

You should have mentioned that earlier. ClientDAO autowiring works well. What’s giving the NullPointerException is session.getCurrentSession()

(Prabodh Kotasthane) #34

Is this because these methods are getting null parameters? If yes then isn’t it the same problem of null beans?

(Sanatt Abrol) #35

No. Look at

“sessionFactory” under property target of Transaction manager is referring to HibernateOAuth2DAO

and you are using the same sessionFactory here(

That’s why sessionFactory.getCurrentSession() is not working in HibernateOAuth2DAO

(Sanatt Abrol) #36

So when you explicitly override the default configuration of “target” in transactionManager, that solves the error as it keeps from nulling the session.

(Sanatt Abrol) #37

It was always a problem of ill-defined HibernateConfiguration and nothing concerning to Autowiring

(Prabodh Kotasthane) #38

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 : sessionFactory is different from this : one right??

(Sanatt Abrol) #39

Exactly what I am saying. sessionFactory works that way. See this ( 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

(Sanatt Abrol) #40

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