hey,
In our project, we are currently
developing with jdk 1.5(using generics)
and we are using hibernate annotations (EJB 3.0).
We have a problem with the SQL generated in a HQL when a single per table inheritance strategy is involved.
Let me explain showing you an example. Starting from a inheritance single per table strategy
as the following example
@Entity
@Table(name="A_TABLE")
@Inheritance()
@DiscriminatorColumn(name="DISCRIMINATOR")
public abstract class A<T> implements java.io.Serializable{
private T value;
private long id;
@Id(generate=GeneratorType.AUTO)
public long getId(){
}
protected void setId(long id){
this.id = id;
}
@Transient
public T getValue(){
return value;
}
public void setValue(T value){
}
// it could appear other methods .....
}
public class StringA extends A<String>{
@Column(name="STRING_VALUE")
public String getValue(){
return super.getValue();
}
}
public class DateA extends A<java.util.Date>{
@Column(name="DATE_VALUE")
public java.util.Date getValue(){
return super.getValue();
}
}
public class NumberA extends A<Number>{
@Column(name="NUMBER_VALUE")
@Basic(temporalType=TemporalType.TIMESTAMP)
public Number getValue(){
return super.getValue();
}
}
we have formulated the following named HQL ::
select a from A as a where a.value=:value
the SQL generated by Hibernate is like this
"select a.id,{other columns} from A_TABLE where a.STRING_VALUE=?"
but for us is not enough because the parameter "value" could be in runtime a string,number or a date
and always would have a look up in STRING_VALUE column from the A_TABLE skipping the NUMBER_VALUE
and DATE_VALUE columns. We are asking if hibernate deals with this kind of feature properly.
We have try to put a formula in the StringA class (more concretly in the method getValue), but we realize that
it is not the correct solution.
thanks a lot!!
Direct trust team
|