Hi,
i have problem with my interface in hibernate.
i think there is a problem with interface, it is possible to use interface in my Map object ?
error message:
nested exception is org.hibernate.MappingException: property mapping has wrong number of columns: com.xxxx.model.HousePropertyValue.value type: object
i have House.java file with mapping of Map collection:
Code:
@OneToMany(mappedBy = "house", fetch = FetchType.LAZY, cascade = CascadeType.ALL,
targetEntity = com.xxx.model.HousePropertyValue.class)
@MapKey(name = "valueKey")
private Map<String, HousePropertyValue> housePropertyValues;
and HousePropertyValue.java (HousePropertyValue interface):
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);
}
and HousePropertyDateValue.java - implementation of HousePropertyValue interface:
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; }
}
hibernate.cfg.xml:
Code:
<hibernate-configuration>
<session-factory>
<mapping class="com.xxx.model.House"/>
<mapping class="com.xxx.model.HousePropertyValue"/>
<mapping class="com.xxx.model.HousePropertyDateValue"/>
</session-factory>
</hibernate-configuration>
thanks!
Ivan