I use hibernate3 and hibernate-annotation in my work
I define a immutable class which name is DateRange,it has two property mapping two column in table. I also define a class DateRangeType which implements CompositeUserType.My question is : how can i writting annotation in order to mapping DateRange to two column in table? I just write like that:
package com.star.sms.model.ppvcatalogue;
import java.util.Date;
import javax.persistence.AttributeOverride;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratorType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.OptimisticLockType;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import com.star.common.customtype.hibernate.DateRangeType;
import com.star.common.customtype.hibernate.StandEnumType;
import com.star.common.customtype.hibernate.StringValueEnumType;
import com.star.common.lang.DateRange;
import com.star.sms.model.core.AbstractHibernateEntity;
import com.star.sms.model.core.Operator;
@Entity()
@Table(name="PPVPRICE")
@org.hibernate.annotations.Entity(
selectBeforeUpdate = false,
dynamicInsert = true,
dynamicUpdate = true,
optimisticLock = OptimisticLockType.VERSION
)
@TypeDefs(
{
@TypeDef(
name="DateRange",
typeClass = DateRangeType.class
)
}
)
public class PpvPrice extends AbstractHibernateEntity {
private Integer priceTypeId;
private String priceType;
private Double price;
private Date creatDate;
private String mem;
private DateRange priceDateRange;
public PpvPrice() {
super(new String[]{"getPriceTypeId"});
}
@Column(updatable = false, insertable = true,
unique = false, name = "CREATDT",
nullable = false)
public Date getCreatDate() {
return creatDate;
}
public void setCreatDate(Date creatDate) {
this.creatDate = creatDate;
}
@Column(updatable = true, insertable = true,
unique = false, name = "MEM",
nullable = true)
public String getMem() {
return mem;
}
public void setMem(String mem) {
this.mem = mem;
}
@Column(updatable = true, insertable = true,
unique = false, name = "PRICE",
nullable = true, length=6, precision=2)
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
@Type(type="DateRange")
public DateRange getPriceDateRange() {
return priceDateRange;
}
public void setPriceDateRange(DateRange priceDateRange) {
this.priceDateRange = priceDateRange;
}
@Column(updatable = true, insertable = true,
unique = false, name = "RICETYPESTR",
nullable = false)
public String getPriceType() {
return priceType;
}
public void setPriceType(String priceType) {
this.priceType = priceType;
}
@Id(generate=GeneratorType.AUTO)
public Integer getPriceTypeId() {
return priceTypeId;
}
public void setPriceTypeId(Integer priceTypeId) {
this.priceTypeId = priceTypeId;
}
}
|