views:

137

answers:

1

Hi,

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.

A: 
  • 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.
Jherico
Do you mean I have to do the string parsing for the queries? Can you please suggest some sample code for the same?
Sandeep Jindal