Hibernate的实践与应用
来源:56doc.com 资料编号:5D15482 资料等级:★★★★★ %E8%B5%84%E6%96%99%E7%BC%96%E5%8F%B7%EF%BC%9A5D15482
资料以网页介绍的为准,下载后不会有水印.资料仅供学习参考之用. 密 保 惠 帮助
资料介绍
Hibernate的实践与应用(中文4700字,英文3200字)
检索对象
从数据库中检索对象是使用Hibernate最有趣(也是最复杂)的部分。Hibernate 提供下列方式
从数据库中提取对象:
导航对象图,从一个已经装载的对象开始,通过像aUser.getAddress().getCity()的属性访问器方法访问相关的对象。如果Session是打开的,当你导航图时,Hibernate会自动装载图的节点。
当对象的唯一标识符值是已知的时候,通过标识符检索是最方便最有性能的方法。
使用Hibernate查询语言(HQL),它是完全面向对象的查询语言。
使用Hibernate 条件API,它提供了类型安全的面向对象的方式执行查询而不需要操纵字符串。这种便利性包括基于例子对象的查询。
Hibernate In Action
Retrieving objects
Retrieving persistent objects from the database is one of the most interesting (andcomplex) parts of working with Hibernate. Hibernate provides the following waysto get objects out of the database:
Navigating the object graph, starting from an already loaded object, byaccessing the associated objects through property accessor methods such as a User.getAddress().getCity(). Hibernate will automatically load (or preload)nodes of the graph while you navigate the graph if the Session is open.
Retrieving by identifier, which is the most convenient and performant method when the uniqueidentifier value of an object is known.
Using the Hibernate Query Language (HQL), which is a full object-orientedquerylanguage.
Using the, Hibernate Criteria API, which provides a type-safe and objectoriented way to perform queries without the need for string manipulation.This facility includes queries based on an example object. |