Sunday, February 12, 2017

Java Persistence API (JPA)

Provides ORM facility for managing relational data in Java applications


  • Entity (equals to a table in a relational DB)
    • Must have a public/ protected no-arg constructor
    • Must not be declared final
  • Entity instance (equals to a table row in a relational DB)
  • Entity Manager Interface 
The EntityManager API creates and removes persistent entity instances, finds entities by the entity’s primary key, and allows queries to be run on entities.


A sample relational mapping is as follows


@OneToOne
@JoinColumns({
    @JoinColumn(name="PARTNUMBER",
        referencedColumnName="PARTNUMBER"),
    @JoinColumn(name="PARTREVISION",
        referencedColumnName="REVISION")
})
public Part getPart() {
    return part;
}

No comments:

Post a Comment