简体   繁体   English

休眠查询

[英]Hibernate Queries

Using Named Queries (located in your hibernate mapping xml file) is a nice way to separate your queries from your buisness logic. 使用命名查询(位于休眠映射xml文件中)是一种将查询与业务逻辑分离的好方法。 But what are the alternatives if your are using Hibernate Annotations for mapping? 但是,如果您使用Hibernate Annotations进行映射,还有哪些选择呢?

Maybe you already know, but there is a @NamedQuery annotation. 也许您已经知道,但是有一个@NamedQuery注释。 However, I can't even convince myself that this has any benefits over hard-coding the query string in an appropriate DAO (provided you are using DAOs and not accessing the session directly - then there could be a case for the @NamedQuery annotation). 但是,我什至无法说服自己,这比在适当的DAO中对查询字符串进行硬编码有什么好处(前提是您使用的是DAO,并且没有直接访问会话-那么@NamedQuery批注可能会出现这种情况) 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM