Java Tutorial/EJB3/Entity Manager
Версия от 17:44, 31 мая 2010; (обсуждение)
Entity Manager: Join Transaction
File: Customer.java
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.Id;
import javax.persistence.PostRemove;
@Entity
public class Customer implements java.io.Serializable {
private String firstName;
private String lastName;
@Id
private long ssn;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public long getSsn() {
return ssn;
}
public void setSsn(long ssn) {
this.ssn = ssn;
}
}
Use Entity Manager To Persist Save Entity Bean
File: Customer.java
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@Entity
@Table(name = "CUSTOMER_TABLE")
public class Customer implements java.io.Serializable {
private int id;
private String lastName;
private String firstName;
private Date timeCreated = new Date();
@Id
@GeneratedValue
@Column(name = "CUST_ID")
public int getId() {
return id;
}
public void setId(int pk) {
id = pk;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@Temporal(TemporalType.TIME)
public Date getTimeCreated() {
return timeCreated;
}
public void setTimeCreated(Date time) {
timeCreated = time;
}
}