here I have a problem that I want to find a solution here, I work on a project using spring mvc and hibernate in my project I have several databases with same architecture (database by company) and a database for authentication, when the user login i have to generates a SessionFactory that corresponds to database of the user company, can you help me by offering me an architecture and give me some examples please, sorry for my English.
相关问题
- How does the JPA handle partial, non-disjoint inhe
- org.apache.commons.fileupload.disk.DiskFileItem is
- Tell hibernate hbm2ddl not create individual table
- Should there be an EntityManager per thread in Spr
- Hibernate and multiThread Logic
相关文章
- spring-mvc a标签带参怎样向controller发送请求。路径格式?
- Hibernate Tutorial - Where to put Mapping File?
- Java spring framework - how to set content type?
- Hibernate doesn't generate cascade
- Java/Spring MVC: provide request context to child
- Spring 5 Web Reactive - Hot Publishing - How to us
- Setup and Tear Down of Complex Database State With
- Spring MVC project not able to publish and run… Me
Depending on which hibernate version you use you can just utilize the built in multi tenant features of hibernate. For that you need to implement the
CurrentaTenantIdentifierResolver
andMultiTenantConnectionProvider
following this documentationthis documentationthe following hibernateProperties have to be set additionaly to use them:
Sample Implementation: CurrentTenantIdentifier:
MultiTenantConnectionProvider:
now just define a datasource per company DB so it can be swapped by the multitenantconnectionprovider.
A call to the sessionFactory in the DAO can be made by using
SessionFactory.getCurrentSession()
or in special cases by usingsessionFactory.withOptions().tenantIdentifier("company01").openSession()
This should cover the basics but might need some tayloring to your application.