Wednesday, April 4, 2012

Apply cascade on hibernate pojo class



import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

/**
 * Gadget generated by hbm2java
 */
@Entity
@Table(name = "gadget", catalog = "gdtracker", uniqueConstraints = @UniqueConstraint(columnNames = "VEHICLE_ID"))
public class Gadget implements java.io.Serializable {

private String gadgetId;
private Guser guser;
private GadgetStatus gadgetStatus;
private Vehicle vehicle;
private Packages packages;
private Date createdDate;
private Date activatedDate;
private Date deletedDate;
private Date expiredDate;
private Set<GadgetTrackingInfo> gadgetTrackingInfos = new HashSet<GadgetTrackingInfo>(
0);

public Gadget() {
}

public Gadget(String gadgetId, GadgetStatus gadgetStatus) {
this.gadgetId = gadgetId;
this.gadgetStatus = gadgetStatus;
}

public Gadget(String gadgetId, Guser guser, GadgetStatus gadgetStatus,
Vehicle vehicle, Packages packages, Date createdDate,
Date activatedDate, Date deletedDate, Date expiredDate,
Set<GadgetTrackingInfo> gadgetTrackingInfos) {
this.gadgetId = gadgetId;
this.guser = guser;
this.gadgetStatus = gadgetStatus;
this.vehicle = vehicle;
this.packages = packages;
this.createdDate = createdDate;
this.activatedDate = activatedDate;
this.deletedDate = deletedDate;
this.expiredDate = expiredDate;
this.gadgetTrackingInfos = gadgetTrackingInfos;
}

@Id
@Column(name = "GADGET_ID", unique = true, nullable = false, length = 45)
public String getGadgetId() {
return this.gadgetId;
}

public void setGadgetId(String gadgetId) {
this.gadgetId = gadgetId;
}

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "USER_ID")
public Guser getGuser() {
return this.guser;
}

public void setGuser(Guser guser) {
this.guser = guser;
}

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "STATUS", nullable = false)
public GadgetStatus getGadgetStatus() {
return this.gadgetStatus;
}

public void setGadgetStatus(GadgetStatus gadgetStatus) {
this.gadgetStatus = gadgetStatus;
}

@Cascade({CascadeType.SAVE_UPDATE})  //applying cascade (means child,parent table records are updated using parent or child object but this obj having relationship).
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "VEHICLE_ID", unique = true)
public Vehicle getVehicle() {
return this.vehicle;
}

public void setVehicle(Vehicle vehicle) {
this.vehicle = vehicle;
}

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "PACKAGE")
public Packages getPackages() {
return this.packages;
}

public void setPackages(Packages packages) {
this.packages = packages;
}

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "CREATED_DATE", length = 19)
public Date getCreatedDate() {
return this.createdDate;
}

public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "ACTIVATED_DATE", length = 19)
public Date getActivatedDate() {
return this.activatedDate;
}

public void setActivatedDate(Date activatedDate) {
this.activatedDate = activatedDate;
}

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "DELETED_DATE", length = 19)
public Date getDeletedDate() {
return this.deletedDate;
}

public void setDeletedDate(Date deletedDate) {
this.deletedDate = deletedDate;
}

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "EXPIRED_DATE", length = 19)
public Date getExpiredDate() {
return this.expiredDate;
}

public void setExpiredDate(Date expiredDate) {
this.expiredDate = expiredDate;
}

@OneToMany(fetch = FetchType.EAGER, mappedBy = "gadget")
public Set<GadgetTrackingInfo> getGadgetTrackingInfos() {
return this.gadgetTrackingInfos;
}

public void setGadgetTrackingInfos(
Set<GadgetTrackingInfo> gadgetTrackingInfos) {
this.gadgetTrackingInfos = gadgetTrackingInfos;
}

}

No comments:

Post a Comment