Objects:
Offer:
Code:
package ccos;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CollectionId;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.GenericGenerator;
@Entity
@Table(name="OFFERS")
public class OfferVO {
private Integer internalOfferId = 0;
private String offerName;
private List<ProductVO> offerProducts;
@Column(name = "OFFER_NAME")
public String getOfferName() {
return offerName;
}
public void setOfferName(String offerName) {
this.offerName = offerName;
}
@Id
@Column(name = "OFFER_ID", nullable = false)
@GenericGenerator(name="OFF_ID_GENERATOR", strategy="increment")
@GeneratedValue(generator="OFF_ID_GENERATOR")
public Integer getInternalOfferId() {
return internalOfferId;
}
public void setInternalOfferId(Integer internalOfferId) {
this.internalOfferId = internalOfferId;
}
@ManyToMany(fetch=FetchType.EAGER, targetEntity=ProductVO.class)
@JoinTable(name="OFF_REL_PRO", joinColumns = {
@JoinColumn(name="OFFER_ID", insertable=true, nullable=true, updatable=true) }, inverseJoinColumns = {
@JoinColumn(name="PRODUCT_ID", insertable=true, nullable=true, updatable=true) })
@GenericGenerator(name="OFF_REL_PRO_ID_GENERATOR", strategy="increment")
@CollectionId(
columns=@Column(name="OFFER_PRODUCT_ID"),
type = @org.hibernate.annotations.Type(type = "long"),
generator="OFF_REL_PRO_ID_GENERATOR")
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.DELETE_ORPHAN, org.hibernate.annotations.CascadeType.ALL})
@Fetch(FetchMode.JOIN)
public List<ProductVO> getOfferProducts() {
return offerProducts;
}
public void setOfferProducts(List<ProductVO> offerProducts) {
this.offerProducts = offerProducts;
}
}
Product:
Code:
package ccos;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
@Entity
@Table(name="PRODUCTS")
public class ProductVO {
private Integer internalProductId = 0;
private String productName;
@Column(name = "PRODUCT_NAME")
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
@Id
@Column(name = "PRODUCT_ID", nullable = false)
@GenericGenerator(name="PRO_ID_GENERATOR", strategy="increment")
@GeneratedValue(generator="PRO_ID_GENERATOR")
public Integer getInternalProductId() {
return internalProductId;
}
public void setInternalProductId(Integer internalProductId) {
this.internalProductId = internalProductId;
}
}