title: Spring JPA + dynamically switch the datasource between schemas in postgresql
body: <p>I have to modify design of the existing application according to following manner, </p>
  
  <p><img src="https://i.stack.imgur.com/hXv0u.jpg" alt="enter image description here"> </p>
  
  <p>According to above design each project contains it's own schema and that mapping table (project_schema_table) is under main schema. All schemas are under one Postgresql database and in future users will create another new schemas (on demand) for their new projects.</p>
  
  <p>Before displaying login window I have to list all existing projects and once user select his project I have to direct to that project with relevant schema. Other than main schema all other project base schemas are exactly the same.   </p>
  
  <p>This is a desktop application developed with latest versions of java technologies JavaFX, Spring and JPA with Postgresql database. Currently it has only one project related schema and I have to introduce main schema and all other subsequent project base schemas.</p>
  
  <p>I have found similar <a href="https://stackoverflow.com/questions/24807366/dynamically-switching-databases-at-runtime-with-spring-4-hibernate-4-using-abs">stack overflow post</a> but it didn't contains any solution. Whether I can accomplish this task with Spring <a href="http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.html" rel="nofollow noreferrer">AbstractRoutingDataSource</a> ? or is there any other mechanism. Thanks.</p>