Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to move named queries of an entity to another class

I have an entity named Client, And it has some named queries and native named queries. What I want to do is, I want to move this named queries to another class. For that I would like to extend the Client entity by another class ClientQuery. And move all named,native queries to that class. Is it possible to do so?

Client CLASS

@XmlRootElement(name = "CLIENT_DETAILS")
@XmlAccessorType(XmlAccessType.FIELD)
@Entity
@NamedQueries({
    @NamedQuery(name = Client.GET_CLIENT_BYLANGID,
    query = "select T from Client T where T.clientPK.langId=:langId")
})
public class Client implements Serializable {
public static final String GET_CLIENT_BYLANGID = "Client.getClientByLangId";
like image 548
arjuncc Avatar asked Feb 21 '14 10:02

arjuncc


1 Answers

As I understand, you want to know whether it correct to move the @NamedQuery out of the Entityclass to a non-entity class.

I have quickly checked the specification and did not see any restrictions about that. Additionally I have tried to put in an mapping.xml an <named-query> element outside of the <entity> element and it is xml-valid, so it is legal.

like image 185
V G Avatar answered Oct 11 '22 11:10

V G