hi!,
i`m a beginner in hibernate, i have question about annotations informations place, if i use interface and one inherited class.
Code:
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="value_type",
discriminatorType=DiscriminatorType.STRING
)
@Table(name="house_property_value")
@javax.persistence.SequenceGenerator(
name="seq_house_property_value",
sequenceName="s_house_property_value",
allocationSize=1
)
public interface HousePropertyValue extends Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="seq_house_property_value")
public Long getId();
public void setId(Long id);
@Column(name="value_key", nullable = false)
public String getValueKey();
public void setValueKey(String valueKey);
@ManyToOne (fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "fk_house_id", referencedColumnName = "id", nullable = false)
public House getHouse();
public void setHouse(House house);
public Object getValue();
public void setValue(Object value);
}
if i have this interface, it is neccesary to have all annotations instructions here, or it is possible to remove these instruction to inherited class ? Or is there any rules for position of these instructions ?
inherited class:
Code:
@Entity
@DiscriminatorValue("DATE")
@javax.persistence.SequenceGenerator(
name="seq_house_property_value",
sequenceName="s_house_property_value",
allocationSize=1
)
public class HousePropertyDateValue implements HousePropertyValue {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="seq_house_property_value")
private Long id;
private House house;
private String valueKey;
@Column(name="value_date", nullable=false)
private Date value = new Date();
public HousePropertyDateValue() {}
public HousePropertyDateValue(Date value) { this.value = value; }
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
public String getValueKey() { return valueKey; }
public void setValueKey(String valueKey) { this.valueKey = valueKey; }
public House getHouse() { return house; }
public void setHouse(House house) { this.house = house; }
public Date getValue() { return value; }
public void setValue( Date value ) { this.value = value; }
public void setValue( Object value ) { this.value = (Date) value; }
}
thanks!
Ivan