Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Dynamically setting schema name for native queries

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
inside my hibernate.cfg.xml I am mentioning
hibernate.default_schema as schema name (say "testSchema") and it is working with named queries and HQL as expected.But when I am using a native sql query ,say

String queryString= 'select field1 from table1 where field2=100';
SQLQuery queryObj=session.createSQLQuery(queryString).
addScalar("field1 ",Hibernate.STRING);

In that case the schema name(i.e. testSchema)is not getting appended to the table names.
As a work around I had to add the schema name name before the table names.
So the changed code is ,
String queryString= 'select field1 from testSchema.table1 where field2=100';
.....

But it is not the correct approach I guess.If there are 100 queries
and in future my schema name changes, I have to change the schema name at 100 places.
Can anybody provide me the correct implementation ?
 
Ayan Dutta
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any hint from anybody ?
Regards,
Ayan
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic