Java Persistence API - annotations - I

26 July 2008

The Java Persistence API heavily depends on the metadata annotations. The API consists of:

Java Persistence API
The Java Persistence query language
Metadata annotations

An entity is a persistence object. It is coded as a POJO, and marked as an entity with the @Entity (javax.persistence.Entity) annotation. By default, all properties/fields are persisted into the datastore, except those marked with the @Transient annotation. Following example shows few annotations that are used with entity beans.

package university;
 
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Column;
import javax.persistence.Id;
 
@Entity
@Table (name="Dept")
public class Department implements Serializable {
@Id
@Column(name="id", nullable=false)
private String deptId;
@Column(name="name")
private String deptName;
private String location;
 
public void setDeptId(String deptId) {
this.deptId = deptId;
}
 
public String getDeptId() {
return this.deptId;
}
 
public void setDeptName(String deptName) {
this.deptName = deptName;
}
 
public String getDeptName() {
return this.deptName;
}
 
public void setLocation(String location) {
this.location = location;
}
 
public String getLocation() {
return location;
}
..................
..................
}

continued …

del.icio.us:Java Persistence API - annotations - I  digg:Java Persistence API - annotations - I  spurl:Java Persistence API - annotations - I  wists:Java Persistence API - annotations - I  simpy:Java Persistence API - annotations - I  newsvine:Java Persistence API - annotations - I  blinklist:Java Persistence API - annotations - I  furl:Java Persistence API - annotations - I  reddit:Java Persistence API - annotations - I  fark:Java Persistence API - annotations - I  blogmarks:Java Persistence API - annotations - I  Y!:Java Persistence API - annotations - I  smarking:Java Persistence API - annotations - I  magnolia:Java Persistence API - annotations - I  segnalo:Java Persistence API - annotations - I  gifttagging:Java Persistence API - annotations - I

Top Of Page | Trackback

If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.

It will look like this: Java Persistence API - annotations - I

Leave a Reply