Ebean

Ebean borrows from a subset of the JPA specification that allows you to markup how your objects map to the database using Java annotations.

You can hand code your entity classes, or use software such as the Dail Toolkit for the Eclipse IDE to auto-generate classes from your database.

This entity class represents a site user who reviews products on a website. It was generated by Dali:

/**
 * The persistent class for the user database table.
 * 
 */
@Entity
@NamedQuery(name="User.findAll", query="SELECT j FROM User j")
public class User implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @Column(name="sp_id", insertable=false, updatable=false)
    private int userId;

    @Column(name="user_name")
    private String userName;

    @Column(name="email")
    private String email;
    
    //bi-directional many-to-one association to JobReview
    @OneToMany(mappedBy="user")
    private List<ProductReview> productReviews;

    public String getUserName() {
        return this.userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }
    
    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public List<ProductReview> getProductReviews() {
        return this.productReviews;
    }

    public void setProductReviews(List<ProductReview> productReviews) {
        this.productReviews = productReviews;
    }

    public ProductReview addProductReview(ProductReview productReview) {
        getProductReviews().add(productReview);
        productReview.setUser(this);

        return productReview;
    }

    public ProductReview removeProductReview(ProductReview productReview) {
        getProductReviews().remove(productReview);
        productReview.setUser(null);

        return productReview;
    }
}

Notes:

  • The userId field's annotations reflect that it is mapped to a primary key field with auto-increment enabled.
  • The productReviews field illustrates how one to many relationships within the database can be managed.
  • Ebean enhances the bytecode of the getter and setter methods so that appropriate actions against the database occur when they are called.

The annotations allow you to describe complex data relationships.

/**
 * The persistent class for the _ database table.
 * 
 */

Professional Support

If you are intereted in receiving professional support services for Ebean please enter your email below and we will get back to you within 2 days.

We don't send out newsletters so no worrying about spam. Also, we never share your details with anyone.