Home > Back-end >  Could you tell me why SqlSessionFactoryBean is a single instance of SSM? Usually the Dao layer and S
Could you tell me why SqlSessionFactoryBean is a single instance of SSM? Usually the Dao layer and S

Time:09-26

After I configuration SqlSessionFactoryBean, casually find a place to inject this object to a variable, and then through isSingleton method found the factory is a single instance,
So does each dao layer if using SqlSessionFactoryBean sqlsession, access to will have the same sqlsession? .

In addition, the dao layer if not mark for instance, if every request is the same SQL session to handle? Or, in the process of project running, always use only one connection?

Thank elder answer!

CodePudding user response:

I was confused, SqlSessionFactoryBean is sqlsession factory factory...

Ok, now you want to turn to the second question:

Dao layer and service layer without tag for instance, when concurrent access to the transaction still can normal use?

The realization of the dao layer is mybatis created, how marked as many instances?
I added 2 seconds delay to the service layer, and then quickly open the two page requests at the same time, found that the output of the dao implementation class address is the same, that is to say, the concurrent access, the implementation of the dao classes are the same, so whether concurrent access, use the sqlsession is also the same? That's why for transaction control? (@ Transactional, open transaction rollback/submit... )...
To learn is too confused! Thank you for reply!

CodePudding user response:

According to the logic, the dao layer injection is SqlSessionFactory factory, by factory production session,
For example sqlsessionFatory. OpenSession () access, retrieve the source code, will find that each session is new again;
  • Related