Hello All,
I am in the process of migrating an existing object model and data model to use Hibernate, replacing a legacy ORM framework.
The object model and data model use/require a TABLE_PER_CLASS inheritance model.
The problem I have encountered is that the union select query generated by Hibernate is not detecting conflicting data types if the concrete classes define the same column name with a different SQL type.
For example:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class ParentClass {
@Id
private Long id;
}
@Entity
@Table(name = "CHILDA")
public class ChildA extends ParentClass {
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "SOMEDATE")
private Date someDate;
}
@Entity
@Table(name = "CHILDB")
public class ChildB extends ParentClass {
@Temporal(TemporalType.DATE)
@Column(name = "SOMEDATE")
private Date someDate;
}
The problem is that the union query generated will result in something like:
select somedate from childa
union all
select somedate from childb
In DB2 executing this query results in a SQL state 42825, i.e. ambiguous types returned in the union statement, somedate is DATE in one statement and is TIMESTAMP in the other.
My question is has anyone else experienced something similar when using union subclasses and if so how did you overcome the problem?
I acknowledge that it is a rather stupid scenario, the object model designers should have called the properties/columns SOMEDATE and SOMETIMESTAMP. Unfortunately I have to live with the design in the interim and I believe using Hibernate with legacy models that include such flaws is definitely a problem that Hibernate should be able to tackle!
|