Hey all,
I'm playing around trying to learn the hibernate annotations, and have stumbled upon a problem (not annotations-related)
I have an object with a Set of properties, like this :
Code:
@Entity
@Table(name = "OBJECT")
public class DataObject {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Column
private String name;
@ManyToMany(cascade = { CascadeType.ALL })
private Set<Property> properties;
@ManyToOne
private DataObject parent;
@ManyToMany(cascade = { CascadeType.ALL })
private List<DataObject> children;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Set<Property> getProperties() {
return properties;
}
public void setProperties(Set<Property> properties) {
this.properties = properties;
}
public List<DataObject> getChildren() {
return children;
}
public void setChildren(List<DataObject> children) {
this.children = children;
}
}
@Entity
@Inheritance (strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Property {
@Id @GeneratedValue(strategy=GenerationType.AUTO)
private long id = -1;
@ManyToOne
private PropertyType propertytype;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public PropertyType getPropertytype() {
return propertytype;
}
public void setPropertytype(PropertyType propertytype) {
this.propertytype = propertytype;
}
public abstract void setValue(Object o);
public abstract Object getValue();
}
@Entity @Table(name = "TEXTPROPERTY")
public class TextProperty extends Property {
@Column @Type(type="org.hibernate.type.StringClobType")
private String value;
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = (String) value;
}
}
@Entity
@Table (name = "VARCHARPROP")
public class VarcharProperty extends Property {
private String value;
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = (String) value;
}
}
Storing an Object with 1 TextProperty and 1 VarcharProperty goes just fine, but my problem is that when I try to access the properties Set on the DataObject afterwards I get an SQL exception: "expression must have same datatype as corresponding expression". The resulting sql contains the following snippet, which causes the exception :
Code:
select value, propertytype_id, id, 1 as clazz_ from TEXTPROPERTY union all select value, propertytype_id, id, 2 as clazz_ from VARCHARPROP
which fails because value from textproperty is a clob and value from varcharprop is a varchar.
Am I doing something wrong, or is it just not possible to do this when using Hibernate ?
Using Hibernate 3.2.0[/code]