문제

Other than default schema, for some SQL queries I need to access a particular schema. The issue is that the name of that particular schema is different for different environments.

After goggling I found that using this link I am able to specify the schema name in variable. If that’s true that I have following questions:

  1. Will that would for SQL queries in the named query?
  2. How to set the value for the variable names?

Thanks in advance.

도움이 되었습니까?

해결책

  • Create an initializing factory bean which takes two resource locations and on initialization will use one of the resources to execute string replacement in the other, and store the results in a temp file which is the output of the factory bean. Points for style if you make the replacement language raw regex.
  • Create a spring context where you declare an instance of this bean, passing in a resource with all the named queries and a resource which will do the string replacement to provide the environment specific versions of the queries.
  • In the spring context create your SessionFactoryBean to initialize your hibernate SessionFactory, passing in the results of the previous factory bean as a mapping resource so that the converted queries get picked up by the hibernate config.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top