Hobione's Weblog

Living & Breathing in Web 2.0 Era

JPA with Hibernate, Toplink etc…

Conversation with Jason Lee to generate Persistence API Entity class

HobiOne: How do create entity class? Do you write all these or use some script

Jason: Do you already have the schema built in a database?

HobiOne: yes

Jason: Ok…iirc, Eclipse has a plug-in that will do that for you, and there might be some Hibernate utils for that

HobiOne: Netbeans does it too but I was not sure what the standard, use IDE or hand code is

Jason: I don’t think there is a standard. you just use what works for you

HobiOne: So do you use Eclipse to generate?

Jason: I usually hand code, but my schema is either small enough or not defined yet )

HobiOne: Can you create schema and entity class at the same time?

Jason: sure

HobiOne: nice

HobiOne: One more question

Jason: Ok…ask all you want )

HobiOne: By using JPA, I have to use Hibernate or Toplink but if I use Hibernate or Toplink, I don’t have to use JPA, is it correct?

Jason: Right

HobiOne: So, JPA is like a driver, it gives the flexibility to switch Persistence API like Hibernate or Toplink

Jason: it’s an abstraction layer, yes

HobiOne: Does it put any overhead?

Jason: Not that I’ve noticed. I don’t think it does, as it only defines a set of interfaces

HobiOne: Uh ha, I see

Jason: Hibernate, say, then creates a class like HibernateEntityManagerImpl that implements that interface, and you use that, though your reference to it is of type EntityManager.

Some Key terms about Persistence Framework from POJOs in Action:

Persistence framework a.k.a Object/Relational Mapping Framework

Object Model = Domain Model

Encapsulating the business logic: Good candidate to encapsulate the business logic are how to handle transactions, security and remoting.

POJO facade: A better approach uses a POJO facade in conjunction with an AOP-based mechanism such as the Spring framework that manages transactions, persistence framework connections and security. The POJO facade approach simplifies development by enabling all of the business logic to be developed and tested outside the application server.

Handling concurency in database transactions

  1. Isolated database transactions
  2. Optimistic locking
  3. Pessimistic locking

Role in the domain Model

  1. Entities: Object with distinct identity. PendingOrder, Order, Restaurant
  2. Value objects: Objects with no distinct identity. Address, User
  3. Factories: Define methods for creating entities. A Java application creates objects by using the new operator. Sometimes, using the new operator directly is sufficient, but if you need to instantiate a complex graph of objects or you need to vary the types of the objects that are created, then you might need factory. A factory defines methods for creating entities. It encapsulates the mechanism that instantiates a graph of objects and connects them together, which simplifies the client code.
  4. Repositories: Repositories manage collections of entities and define methods for finding and deleting entities which encapsulate the persistence framework
  5. Services: Implemet responsibilities that can’t be assigned to a single class and encapsulate the domain model

Jump Start to JSF JPA: Use Netbean’s tutorial

Advertisements

March 12, 2008 - Posted by | Java Persistence API

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: