Using hibernate default schema as a variable

Given you have set up a default_schema in your hibernate configuration

<hibernate-configuration> 
   <session-factory>
      <property name="hibernate.default_schema">mySchema</property>
   </session-factory>
</hibernate-configuration>

Rather than writing a native SQL query like SELECT x FROM mySchema.tableName you can write your query as SELECT x FROM {h-schema}tableName rather than trying to do a find/replace when your schema name inevitably changes. Note that the . after the schema name is not only not required it will not work if it is added.

Leave a Reply

Your email address will not be published. Required fields are marked *