使用带注释的命名查询所带来的问题。
我选择使用命名查询来说明一个更大的问题。
I have chosen to use named queries to illustrate a much larger problem.
检查从已命名查询返回的结果。
获得关系以及已命名查询的支持
命名查询只是注释如何被过度使用的一个示例。
Named queries are just one example of how annotations can be overused.
命名查询使您能够在单个位置定义一个查询。
Named queries enable you to define a query in a single location. There are many benefits to named queries.
为更正该问题,我使用了Hibernate命名查询。
我可以方便地将命名查询打包在一个方法中,并重复执行它。
I can easily wrap the named query in a method and execute it again and again.
下面是如何定义命名查询,并将其与实体类关联的一个示例?
Below is an example of how you can define a named query and associate it with an entity class.
将每个查找器的命名查询添加到域对象的hbm . xml映射文件。
Add a named query for each finder method to the hbm.xml mapping file for the domain object.
您可以将命名查询定义为注释,并在代码中的其他位置执行它。
You can define a named query as an annotation and execute it somewhere else in the code. Here is an example of using executing this type of named query.
现在,我可以方便地对命名查询进行更改,而无需更改源代码和重新编译。
Now, I can easily make changes to named queries without changing my source code and recompiling.
使用这3个参数来调用已命名查询SLAEndpointLookup。
Uses these three parameters to call the named query SLAEndpointLookup.
Hibernate不为命名查询提供任何真正的名称空间功能。
Hibernate provides no real namespace functionality for the named queries.
如果您想要改变已命名查询自身的话,它能使您避免更改所有的参考。
It keeps you from having to change all references to a query if you happen to change the named query itself.
从SOAPHeader中的特定位置提取已命名查询的3个参数。
Extracts the three parameters for the named query from specific locations in the SOAP Header.
在清单7中,我们在定义了一些基本的已命名查询后实例化这个解析器。
In Listing 7, you can see where we instantiate this resolver after defining some basic named queries.
使用从中介流调用的已命名查询中使用的3个参数的值初始化处理程序。
Initialises the handler with the values for the three parameters to be used in the named query called from the mediation.
对所有的命名查询在初始化的时候执行验证,任何无效的查询会抛出异常。
Will perform validation on all named queries at initialization time, and throw if any is not valid.
还可以使用FinderNamingStrategy来支持其他命名查询的方法。
You could also use a FinderNamingStrategy to enable other ways of naming queries.
这个样例的结果解析器然后将这个语句解析为一个我们预先定义的已命名查询。
The sample's result resolver will then resolve this statement to a named query which we predefined as.
遵从命名查询的风格,目标是等同或超过现有对象-关系映射器和持久化解决方案的功能。
Follows the named-query style, targeted to match or exceed the capabilities of existing object-relational mappers and persistence solutions.
Department实体创建的每一个已命名查询,都将会有一个与之相对应的查询方法。
There will be a corresponding query method for each named query that was created on the Department entity.
其主要优点是查询的外部化,因此,带注释的命名查询(如果有)几乎没有任何意义。
The major benefit is the externalization and, therefore, an annotated named query makes little sense, if any.
QueryStatement区域显示出了,该方法将会采用的实际已命名查询。
The query Statement area shows the actual named query that will be performed by this method.
还可以使用As子句命名查询中的选定列,从而允许您控制如何显式结果,这也在下一节中讲述。
You can also use an AS clause to name the selected columns in a query. Doing so lets you control how the results are displayed, which is also demonstrated in the next section.
这个集合解析器查询用户提供的已命名查询,附加位置参数,并针对数据库执行JDBC语句。
This collection resolver looks up the named query as provided by the user, attaches the position parameters, and executes JDBC statements against the database.
let子句从执行清单6中定义的已命名查询之后DB 2返回的信用违约掉期数据集合中摘取所引用的实体信息。
The LET clause extracts referenced entity information from the collection of credit default swap data that DB2 returns after executing the named query defined in Listing 6.
这些标识符的使用和定义方式特定于您自己的安装,但是对这些标识符在这个已命名查询中的使用方式的理解应该告知您的命名策略。
How these identifiers are used and defined is specific to your own installation, but an understanding of how these are used in this named query should inform your naming strategy.
在本文中,将检查JPA中的各种查询样式,解释它们存在的原因,并解释为什么对某些样式(如命名查询)进行注释没有任何意义。
In this commentary, I will examine the various query styles in JPA, rationalize why they exist, and explain why certain styles (such as named queries) just make no sense to be annotated.
应用推荐