CS6320:  SW Engineering of Web Based Systems

 

Java Persistance API (JPA)

javax.persistence package   
  • The Java Persistence API deals with the way relational data is mapped to Java objects ("persistent entities"), the way that these objects are stored in a atabase so that they can be accessed at a later time, and the continued existence of an entity's state even after the application that uses it ends.

  • Java Persistence API standardizes object-relational mapping.

  • Provides Object-oreinted interface to data (even if underlying database is not an object store)

    Google App Engine Note:

    Supported for use in Google App Engine to access the Google App Engine Datastore (object database)

Entity

A lightweight Java Class whose state is tied either to

  • a row (data base entry) in a relational database table
  • an object entry in a object database (GAE Entity)

Example

 
import java.util.Dateimport java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Book {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String title;
    private String author;
    private int copyrightYear;
    private Date authorBirthdate;
    public Long getId() {
        return id;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }     public String getAuthor() {
        return author;
    }
    public void setAuthor(String author) {
        this.author = author;
    }
         public int getCopyrightYear() {
        return copyrightYear;
    }
    public void setCopyrightYear(int copyrightYear) {
        this.copyrightYear = copyrightYear;
    }
         public Date getAuthorBirthdate() {
        return authorBirthdate;
    }
         public void setAuthorBirthdate(Date authorBirthdate) {
        this.authorBirthdate = authorBirthdate;
    }
}

 

 

© Lynne Grewe