Understanding JPA, 1
来源:互联网 发布:java如何获取当前日期 编辑:程序博客网 时间:2024/05/21 00:49
Numerous projects have sought to make the datapersistence layer a good object-oriented citizen in Java applicationdevelopment. The Java Persistence API, an outgrowth of JSR 220,collects and standardizes that work. In this first half of a two-partintroduction to the Java Persistence API, learn how JPA tames theprocess of writing code that manipulates data, making it a more naturalpiece of your object-oriented architecture.
Likeit or not, data is an integral part of any application, even coolobject-oriented ones. Everything stops at the persistence layer, whereJava developers traditionally have had to write complex SQL queries,which can become unmanageable as the application grows. How good itwould be if you could just treat these queries as objects, and applyobject-oriented programming concepts like encapsulation, abstraction,inheritance, and polymorphism to them! With such an abstraction, youcould hide the complexity of the underlying data store.
In fact, the Javacommunity has produced numerous object-oriented approaches to datapersistence: EJB, JDO, Hibernate, and Toplink are all worthy solutionsthat have tackled this problem. The Java Persistence API, or JPA, is astandard persistence API introduced as part of the Java EE 5 platform.The JPA specification was first introduced as part of JSR 220: EJB 3.0, with the goal of simplifying the EJB entity beans programming model. Although it all started with entity beans and is packaged with Java EE 5.0, JPA can be used outside the container in a Java SE environment.
Inthis article, you will see how elegantly data persistence can behandled in an object-oriented manner just with the help of JPAannotations. The article is intended for readers new to JPA whounderstand the basic concepts of relational database management systemsand are familiar with Java 5 annotations. JPA requires Java 5 orhigher, as it makes heavy use of new Java language features such asannotations and generics.
OpenJPA and the example application
Concepts in this article are explained and demonstrated using OpenJPA,an open source JPA implementation from Apache. I chose OpenJPA overother vendor product because it has been integrated with the Weblogic,WebSphere, and Geronimo application servers. The current version ofOpenJPA at the time of writing is 1.0.1; there's a link to the binarydistribution in the Resources section. If you're going to use a different setup, obviously you'll need to check out the documentation first.
Theremainder of this article will explore various object-oriented JPAconcepts with a sample application that implements functionality for asimple development scenario. Imagine there's a superstore called XYZwith both an online and retail customer base. To begin, you will seehow to apply CRUD operations to this customer model using JPA. In thelater sections, you'll see how you can extend the CRUD operations usingobject inheritance -- the JPA way.
The code package for this article includes sample code for entity listeners and all three inheritance types (single table, joined, and table per class) discussed in the article, implemented in the context of the example application.
- Understanding JPA, 1
- Understanding JPA, 2
- Understanding JPA,3
- Understanding JPA,4
- Understanding JPA, 5
- Understanding JPA, 6
- Understanding COM Apartments(1)
- Understanding
- jpa学习1---jpa入门
- Chapter 1---Understanding Global Concepts
- 1 getting started &understanding react
- JPA系列1-JPA环境搭建
- 学习笔记:Understanding Layouts in SWT(1)
- TRULY Understanding Dynamic Controls (Part 1)
- TRULY Understanding Dynamic Controls (Part 1)
- 1Understanding How Expression Web Works
- <<Understanding SNMP MIBs>> 部分翻译 (1)
- understanding linux usb ehci device driver(1)
- 忘了root密码怎么办(Fedora 8)
- AQtime实战
- C# 绘图中的图片闪烁问题解决方法的使用结果
- 关于次贷款与金融危机的英语学习
- 请看废柴俺
- Understanding JPA, 1
- Understanding JPA, 2
- 自定义GridView 介绍
- Understanding JPA,3
- Understanding JPA,4
- Understanding JPA, 5
- Understanding JPA, 6
- 详解.NET中的动态编译
- Head First C# 中文版 图文皆译 第十一章 事件和代理 page490