-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Named Queries / XDoclet best practice
PostPosted: Fri Oct 31, 2003 1:27 pm 
Newbie

Joined: Wed Oct 15, 2003 11:16 am
Posts: 6
I have a number of hibernate queries used in a service layer which I would like to externalize into named queries in the mapping xml, and refactor the usages to the form:

Query q = getNamedQuery(String query);

I use XDoclet to generate all the mappings, using a single mapping doc per class.

My questions are:

1) Given that the mappings are all XDoclet-generated, is my only option to provide merge docs for the <query/> elements I want to include into my mappings?

2) What is a common practice of locating the named queries? I find that some of the queries I want to externalize don't neatly fit into a particular persistent class' mapping; they involve several classes, and it seems awkward to stuff them into any given one. Is there a tip to de-couple the named query xml from a particular mapping file?

It would be useful to independently organize a collection of related named queries together, and use a configurations for different applications that include those queries along with the mappings they rely on.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2003 3:43 pm 
Regular
Regular

Joined: Tue Sep 16, 2003 11:35 am
Posts: 93
Location: San Francisco, CA
So I assume you have a .hbm.xml file for each class and are packaging them into a jar file.

I think you should just be able to add yet another .hbm.xml file into the directory structure that is jar'ed. Call it MyQueries.hbm.xml or something. Then name your queries however you'd like, the query namespace is totally independent of any class package namespace, the name of the query just has to match the string to send to getNamedQuery().


Top
 Profile  
 
 Post subject: T
PostPosted: Fri Oct 31, 2003 4:07 pm 
Newbie

Joined: Wed Oct 15, 2003 11:16 am
Posts: 6
Thanks.

I misread the DTD, and thought that the <class/> was a REQUIRED child of <hibernate-mapping/>.

I'll give that a go - collect queries into mapping file independent of any mapped <class/> elements.

Having the <query/> bound to <class/> in the mapping really didn't make sense to me. I should have known it wasn't so! ;-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.