Hibernate的实践与应用-毕业设计(论文)外文资料

上传人:206****923 文档编号:91573285 上传时间:2019-06-30 格式:DOC 页数:13 大小:74.52KB
返回 下载 相关 举报
Hibernate的实践与应用-毕业设计(论文)外文资料_第1页
第1页 / 共13页
Hibernate的实践与应用-毕业设计(论文)外文资料_第2页
第2页 / 共13页
Hibernate的实践与应用-毕业设计(论文)外文资料_第3页
第3页 / 共13页
Hibernate的实践与应用-毕业设计(论文)外文资料_第4页
第4页 / 共13页
Hibernate的实践与应用-毕业设计(论文)外文资料_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《Hibernate的实践与应用-毕业设计(论文)外文资料》由会员分享,可在线阅读,更多相关《Hibernate的实践与应用-毕业设计(论文)外文资料(13页珍藏版)》请在金锄头文库上搜索。

1、毕业设计(论文)外文资料原文及译文专 业 计算机科学与技术班 级 学 号 姓 名 指 导 教 师 原文出处:Hibernate in ActionHibernate In ActionCHRISTIAN BAUERGAVIN KINGRetrieving objectsRetrieving persistent objects from the database is one of the most interesting (andcomplex) parts of working with Hibernate. Hibernate provides the following waysto

2、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 gr

3、aph 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

4、type-safe and objectoriented way to perform queries without the need for string manipulation.This facility includes queries based on an example object. Using native SQL queries, where Hibernate takes care of mapping the JDBC result sets to graphs of persistent objects.In your Hibernate applications,

5、 youll use a combination of these techniques.Each retrieval method may use a different fetching strategythat is, a strategy that defines what part of the persistent object graph should be retrieved. The goal is to find the best retrieval method and fetching strategy for every use case in your applic

6、ation while at the same time minimizing the number of SQL queries for best performance.We wont discuss each retrieval method in much detail in this section; instead well focus on the basicfetching strategies and how to tune Hibernate mapping files for best default fetching for all methods. Before we

7、 look at the fetching strategies, well give an overview of the retrieval methods. (We mention the Hibernate caching system but fully explore it in the next chapter.) Lets start with the simplest case, retrieval of an object by giving its identifier value (navigating the object graph should self-expl

8、anatory). You saw a simple retrieval by identifier earlier in this chapter, but there is more to know about it.Retrieving objects by identifierThe following Hibernate code snippet retrieves a User object from the database:User user = (User) session.get(User.class, userID);The get() method is special

9、 because the identifier uniquely identifies a single;instance of a class. Hence its common for applications to use the identifier as aconvenient handle to a persistent object. Retrieval by identifier can use the cachewhen retrieving an object, avoiding a database hit if the object is already cached.

10、Hibernate also provides a load() method:User user = (User) session.load(User.class, userID);The load() method is older; get() was added to Hibernates API due to userrequest. The difference is trivial: If load() cant find the object in the cache or database, an exception isthrown. The load() method n

11、ever returns null. The get() method returnsnull if the object cant be found. The load() method may return a proxy instead of a real persistent instance.A proxy is a placeholder that triggers the loading of the real object when its accessed for the first time; we discuss proxies later in this section

12、. On the other hand, get() never returns a proxy.Choosing between get() and load() is easy: If youre certain the persistentobject exists, and nonexistence would be considered exceptional, load() is a good option. If you arent certain there is a persistent instance with the given identifier, use get(

13、) and test the return value to see if its null. Using load() has a further implication: The application may retrieve a valid reference (a proxy) to a persistent instance without hitting the database to retrieve its persistent state. So load() might not throw an exception when it doesnt find the pers

14、istent object in the cache or database; the exception would be thrown later, when the proxy is accessed.Of course, retrieving an object by identifier isnt as flexible as using arbitrary queries.Introducing HQLThe Hibernate Query Language is an object-oriented dialect of the familiar relational query

15、 language SQL. HQL bears close resemblances to ODMG OQL andEJB-QL; but unlike OQL, its adapted for use with SQL databases, and its much more powerful and elegant than EJB-QL (However, EJB-QL 3.0 will be very similar to HQL.) HQL is easy to learn with basic knowledge of SQL. HQL isnt a data-manipulat

16、ion language like SQL. Its used only for object retrieval, not for updating, inserting, or deleting data. Object state synchronization is the job of the persistence manager, not the developer.Most of the time, youll only need to retrieve objects of a particular class and restrict by the properties of th

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 中学教育 > 其它中学文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号