This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
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

Where should we keep the Native SQL queries

 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using couple native SQLs queries in Hibernate3. Right now I have kept them into Java file. But my boss told me that if there is any change into queries then you would need to change the query,compile Java file and restart the server. Which is not desirable in production server at client end. So he asked me to keep it in properties file so that you don't need to restart the server. I just want to know that is this the correct way to do it? How do you do that?
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this is a good question. I was looking over a discussion of the porting of the JavaRanch/CodeRanch to JForum, and noticed this comment from


JR: Was there anything in the code that made you say, oh cool, I like the way they did that!
Jeanne: I really like that all the SQL is in one property file with overrides for database specific ones.


So, apparently this is how JForum approached the topic, and it seems that some of the JavaRanch heavyweights seem to have been impressed by the approach.

Of course, JForum isn't using Hibernate, but I think the point remains the same, and that is that having everything isolated in one, single, easy to maintain property file can be a good solution.

Opinions?

-Cameron McKenzie
 
Leonardo Carreira
Ranch Hand
Posts: 494
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..

sorry iam newbie.. your question is made me to do good design..

sorry maybe i need some suggestions about :
what kind of Hibernate do you use?..
is it Hibernate Annotation?, and How to save the queries in the properties file?..
do you use XML mapping file?..
is it possible to change the queries in XML Mapping file, while running time?..

Thanks in advance...
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a big fan of Hibernate with JSP Annotations, but sometimes there is a case to be made for one hibernate-config.xml file that contains all of your mappings in a single place. To each his own, as they say.

Expecting to change the SQL at runtime might be a little too much. For extremely flexible queries, use the Hibernate Criteria API. I pulled a little bit out of my book on Hibernate and put it on my website. You should take a look if you want to learn more about the Criteria API:

Matering the Hibernate Criteria API: Tutorials and Examples

-Cameron McKenzie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic