如何在单独的文件中创建命名查询 [英] How do I create Named Queries in a Separate file
本文介绍了如何在单独的文件中创建命名查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将所有命名查询保留在单独的文件中.例如
I need to keep the all the named queries in a separate file. For example
@javax.persistence.NamedQueries({
@NamedQuery(name = "Employee.findAll", query = "SELECT e FROM Employee e")})
public class AllNamedQueries {
}
现在,其本身会导致很多错误命名查询只能在Entity或MappedSuperClass类中定义".
Now that much in itself causes an Error "Named queries can only be defined in Entity or MappedSuperClass class".
如何在单独的文件中创建命名查询?分别表示实体文件以外的文件.
How do I create Named Queries in a Separate file? By separate I mean files other than entity file.
推荐答案
您可以使用orm.xml
来定义XML中的JPA映射.这种方法是等效的,并且会覆盖注释.
You can use orm.xml
that allows you to define JPA mappings in XML. This approach is equivalent and overrides annotations.
基于使用jpa和hibernate在orm.xml中定义命名查询的示例:
<entity class="com.example.Employee">
<table name="Employee.findAll" />
<named-query name="findAll">
<query><![CDATA[
SELECT e
FROM Employee e
]]></query>
</named-query>
</entity>
这篇关于如何在单独的文件中创建命名查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文