• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Externalizing SQL statements in JEE

 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all:

We are using Hibernate as an ORM to build a JEE application.
I want to know if putting the HQL in an external file is a good idea.
If it is, why? and how it can be implemented?

Thanks
 
Jan Cumps
Bartender
Posts: 2586
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't do it. To my feeling, the queries belong to the code. So I want them as close to the code as possible. It makes things easier to understand.
I do externalize internationalization-sensitive things, like messages.

There are other opinions around.

If you want to externalize your queries, you could use Property files or a ResourceBundle.

Regards, Jan
[ April 27, 2007: Message edited by: Jan Cumps ]
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34218
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hanna,
It's a matter of personal preference.

I find it useful to put things that might change, like the schema name, in a property file. If the queries are highly static, it could make sense to put them in a property file.

I tend to do more dynamic queries and like them closer to the code. Also, if I change the query, I usually need to change the code (prepared statement or resultset), so it's helpful to have them in the same place.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic