JEE-persistence API (JPA)

JEE/ Java enterprise edition

JPA Java persistence

@CollectionTable is used to mapping of collections of basic or embeddable types.@Entity is allows collections of simple objects to be easily defined.

The entity’s persistent state is defined by four field, the identity id defined by the field id and is annotated with @id. A composite primary key may also be defined where the primary key corresponds to ome or more fields of the entity class. 

the implements  Serializable interface, and that allows it to be passed by value through a remote interface.

The relationships between different entities are defined using @OneToOne, @OneToMany, @ManyToOne and @ManyToMany annotation on the corresponding field of the referencing entity.

Validating the Entities.

validation has some predefined constraints like @Min, @Max, @Pattern and @Size.

@Entity
public class Student implements serializable {

@Id
private int id;

@Size(max=30)
private String name;

@Size(min=3, max=10)
private String grade;

@Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\."
        +"[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@"
        +"(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?",message="{invalid.email}")
protected String email;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s