Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Where should we keep the Native SQL queries

 
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?
 
author and cow tipper
Posts: 5000
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
 
Ranch Hand
Posts: 494
Eclipse IDE Postgres Database Java
  • 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
Posts: 5000
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
 
Something must be done about this. Let's start by reading this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic