Hibernate的实践与应用
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.
[资料来源:http://Doc163.com]
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.
[来源:http://Doc163.com]