6

I am porting a legacy application to hibernate 5 and I'm having trouble with the login phase. Here's how it works (I can't change that):

  • user initially connects to oracle DB with a generic login/password (same for all users)
  • then user runs a "login" stored procedure and enters a unique password as parameter
  • the procedure returns a specific Oracle DB username/password to the user
  • user disconnects from DB and reconnects using the credentials given by the stored procedure

I currently create one instance of sessionFactory per connected user, but I'm worried that this will impact performance. Is there a better way to do this?

Thanks

user2711115
  • 457
  • 3
  • 18
  • Have you looked at https://stackoverflow.com/questions/14411860/why-use-only-one-sessionfactory-object-per-application. It explains the merits for having to have implemented the Factory design pattern. – worker_bee Jul 20 '17 at 04:36
  • Yes I have thank you. But how to have one session factory instance with different login/passwords? – user2711115 Jul 20 '17 at 07:08
  • This is essentially the same issue as here https://stackoverflow.com/questions/7520583/hibernate-multiple-users-dynamically-changing and there doesn't seem to be any other way than use multiple SessionFactories... – user2711115 Jul 20 '17 at 07:24
  • > but I'm worried that this will impact performance. How do you know that it would impact performance? Having said that, if you configure your `SessionFactory` properly, nothing to worried about it. > Is there a better way to do this? No. And as mentioned by others and links above, one user per `SessionFactory` is correct approach to your requirement. – xsalefter Jul 20 '17 at 23:34

1 Answers1

1

Hibernate Multitenancy with "Separate database" strategy would work even if you are actually connecting to the same database but different credentials. MultiTenantConnectionProvider must be specified to return connection with right username and password.

ikettu
  • 1,123
  • 11
  • 17