Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamically setting schema name for native queries

 
Ayan Dutta
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic