Primer for OpenJPA

OpenJPA is the open source implementation of Java Persistence API. It has been integrated with the Weblogic, WebSphere, and Geronimo application servers. JPA provides an agnostic Java-based API for storing and retrieving information to a backend database. It has a canonical query language named Java Persistence Query Language, or JPQL, that blends with the programming methods of Java and eliminates the need to tailor database queries for a particular database. However, JPA also supports native SQL which can be used for quick ports with a known backend database.

You'll need three artifacts to implement a JPA-compliant program:

  • An entity class
  • A persistence.xml file
  • A class through which you will insert, update, or find an entity
Since JPA is all about entity-relationship mapping, need to take a look at the design of the entity object. The entity object is nothing but a POJO class marked as an entity with the @Entity annotation.

  • JPA allows persistent classes to inherit from non-persistent classes, persistent classes to inherit from other persistent classes, and non-persistent classes to inherit from persistent classes.
  • The entity class should have a default no-argument constructor.
  • The entity class should not be final.
  • Persistent classes cannot inherit from certain natively-implemented system classes such asjava.net.Socketandjava.lang.Thread.
  • If a persistent class inherits from a non-persistent class, the fields of the non-persistent super class cannot be persisted.
JPA provides callback methods for performing actions at different stages of persistence operations. JPA provides listeners for these kinds of activities before and after each fetch, insert, or update operation. The callback methods can be annotated as any of the following:

  • @PostLoad
  • @PrePersist
  • @PostPersist
  • @PreUpdate
  • @PostUpdate
  • @PreRemove
  • @PostRemove

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值