Wednesday, June 30, 2010

JPA Entity Beans

Entities in JPA (Java Persistence API) is simply a lightweight persistence object that represents a row in a relational database table. Each entity class is annotated with javax.persistence.Entity and must have a no-args constructors like an ordinary JavaBeans classes. The entity class must not be declared final and also the persistence field of your entity class must not be declared final. Below is a simple possible entity class:

import java.util.ArrayList;
import java.util.List;
import javax.persistence.*;

public class OrderDetails
    implements Serializable, OrderInjection {

    private List<EmbeddedPLU> items;

    public OrderDetails() {

    public void setItems(List<EmbeddedPLU> items) {
        this.items = new ArrayList<EmbeddedPLU>(items);

    public List<EmbeddedPLU> getItems() {
        return this.items;

As we can see entity classes are just plain Java classes annotated with javax.persistence.Entity and that is the basics creating JPA entity classes.

Thank you and happy reading .",)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.