JPA with Hibernate, Toplink etc…
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
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
- Isolated database transactions
- Optimistic locking
- Pessimistic locking
Role in the domain Model
- Entities: Object with distinct identity. PendingOrder, Order, Restaurant
- Value objects: Objects with no distinct identity. Address, User
- 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.
- Repositories: Repositories manage collections of entities and define methods for finding and deleting entities which encapsulate the persistence framework
- 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
No comments yet.
Leave a comment
-
Archives
- November 2009 (1)
- July 2009 (1)
- June 2009 (5)
- May 2009 (2)
- April 2009 (4)
- March 2009 (2)
- January 2009 (3)
- December 2008 (1)
- November 2008 (2)
- October 2008 (1)
- September 2008 (3)
- August 2008 (2)
-
Categories
-
RSS
Entries RSS
Comments RSS