Hi,
I have following problem, there are several
Code:
@MappedSuperclass
abstract class Base<TID, T> {
TID id;
T data;
@Transient
abstract getId();
@Transient
abstract getData;
}
@Entity()
@Table(...)
@Inheritance(strategy = SIMPLE_TABLE)
@SequenceGenerator(...)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.INTEGER)
abstract class Value<T> extends Base<Long, T> {
@Id()
@GeneratedValue(...)
....
public interface Type{
int VARCHAR = 1;
int NUMERIC = 2;
}
String propertyName;
@ManyToOne
@JoinColumn(name = "componentId")
public Component getComponent() {
return component;
}
@Entity()
@DiscriminatorValue(Type.VARCHAR)
public static class Varchar extends Value<String> {
@Override
@Column(name="dataString")
String getData() {
return data;
}
}
@Entity()
@DiscriminatorValue(Type.NUMERIC)
public static class Numeric extends FValue<Long> {
@Override
@Column(name="dataLong")
public Long getData() {
return data;
}
}
}
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
class Component{
protected Long id;
private Map<String, FValue<?>> values = new HashMap<String, FValue<?>>();
@OneToMany(mappedBy = "component")
@MapKeyColumn(name = "propertyName")
public Map<String, FValue<?>> getValues() {
return values;
}
}
Others entities like Element extends Component.
I'd like do something like this
Code:
select comp, v from Component comp inner join comp.values v where v.propertyName = 'exampleName' and v.data = 'example';
Of course i know that, hibernate doesn't know type of values, but I can imagine casting or translate this to sql like this (value.type = 1 and value.dataString = 'example') or (value.type = 2 and value.dataLong = 'example') in where clause.
We can do this that
Code:
select comp, fv from Component as comp inner join comp.values as fv where comp.values['dpLongDesc'] in (select a.id from FValue$Numeric where a.data = :str)
but it multiplies amout of select that is not optimal.