For every http request there is tenant identifier based on which the schema is switched (datasource switching).


Now to secure the data access I am introducing role per schema using below code in my method getConnection ()

connection.createStatement().execute("SET ROLE " + role);

Is there any other alternative way/recommended way to set the role ?

  • What's wrong with execute("SET ROLE " + role)? Why are you looking for an alternative?
    – mustaccio
    Nov 7 at 16:06
  • Same reason as I did not use setting up schema using postgres command, I used method given in java dependency. In case I use a different DB other than postgres and the command changes then it will be taken care by the java dependency and there will be no change in my code.
    – Subhajit
    Nov 7 at 18:42


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.