-->
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.  [ 2 posts ] 
Author Message
 Post subject: NamedQuery possible location
PostPosted: Wed May 28, 2008 11:18 am 
Newbie

Joined: Tue May 22, 2007 3:39 am
Posts: 15
Hello,

In Our project we have about 10 branches. I would like move all NamedQuery to separate one file for each branch.
Is possible locate NamedQuery in not domain file ?


regard
gienas


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 28, 2008 1:23 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
If you're using JPA annotations, the class with the @NamedQuery annoation must be added to the AnnotationConfiguration object when it is initialized/configured.

Quote:
One thing you should know about named queries is that the class that defines the @NamedQuery tag must be made part of Hibernate's AnnotationConfiguration object. Our User class is added to the AnnotationConfiguration object in our custom HibernateUtil class, so we'll add the NameQuery right before the class declaration of the User.

package com.examscam.model;
import javax.persistence.*;
import org.hibernate.Session;
import com.examscam.HibernateUtil;
@Entity
@Table(name = "user", schema = "examscam")
@NamedQuery(name="user.findByLoginName",
query="from User where loginName = :name" )
public class User { }

Once you have defined your @NamedQuery, and the class in which it is defined is loaded into Hibernate's AnnotationConfiguration, you can use this named query anywhere that you access the Hibernate Session.


[url]http://www.thebookonhibernate.com/HiberBookWeb/learn.jsp?tutorial=08masteringhqlandnamedqueries[url][/url]

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.