Chapter 7. Leveraging JPA and Hibernate with Flex

Java is an object-oriented programming language and as such, applications built using it model domain entities as objects. Objects encapsulate data and behavior together and provide the familiar real-world semantics to interact with it. A majority of modern-day applications store persistent data in popular data storage engines like databases, most of which are relational in nature.

The world of objects and the world of relational entities view the same context from different perspectives, so mismatches exist between them. I will present a small example and illustrate some of the most common problems related to this mismatch. However, indulging in a thorough discussion on this topic is beyond the scope of this chapter.

Before I start digging into the example, it is worthwhile to state up front that the best known solution to the problem comes from the breed of tools classified under the Object Relational Mapping (ORM) category. Such tools reduce the impedance to the flow and data interchange between the objects and the relational formats. Hibernate is one such open source Java-based ORM solution. Hibernate is both extremely popular and well liked by Java developers.

Java Persistence API (JPA) is a Java Community Process (JCP)–created standard specification that defines the contracts and interfaces for ORM between Java and the relational world. Hibernate is a JPA implementation and so are TopLink and OpenJPA. Hibernate has features that go beyond the JPA and so can be thought of as a superset of JPA.

Flex applications are programmed in ActionScript 3 (AS3). AS3, like Java, is an object-oriented language. Therefore, the object/relational impedance mismatch becomes relevant in Flex applications as well. In the set of Flex applications that connect to data stores through a Java middle tier, most of the bridging between the two worlds of objects and relational data is the responsibility of the Java layer. Therefore, Flex applications, with a Java middle tier or service layer, can leverage JPA and Hibernate as an ORM solution. Custom extensions to BlazeDS can make loading, storing, updating, and the propagation of domain model objects through the chain, from the rich client to the database connector, smooth and seamless. This chapter concentrates on such extensions and explains how they work with JPA and Hibernate.

Next, we go back to the topic of object relational mismatch and walk through an example to understand the problems.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.37.10