I've got a JOINED subclass that uses @AttributeOverride to override the name of the column containing the id, but in the generated query that joins the tables, the base class column name appears everywhere.
Hibernate Annotations 3.4.0GA, Windows XP, Oracle 10g.
Here's the base class:
Code:
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="entityType")
@Table(name="BASE")
public abstract class Base {
@Id
@Column(name="BASE_ID")
@GeneratedValue
private Long id;
...
}
and here's the subclass:
Code:
@Entity
@Table(name="SUBCLASS1")
@DiscriminatorValue("SUBCLASS1")
@AttributeOverride(name="id", column=@Column(name="SUB_ID"))
public class Subclass1 extends Base {
...
}
Here's the DAO method that fetches all Subclass1 entities:
Code:
@SuppressWarnings("unchecked")
public List<Client> getAllSubclass1() {
List list = getSession()
.createCriteria(Subclass1.class)
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
.addOrder(Order.asc("name"))
.setFetchMode("anassociation", FetchMode.LAZY)
.setFetchMode("anotherassociation", FetchMode.LAZY)
.list();
return list;
}
Here's the query that is generated:
Code:
SELECT this_.base_id AS base1_0_0_,
this_1_.discriminator AS discrimi2_0_0_, this_.NAME AS name1_0_,
this_.originalid AS originalid1_0_
FROM subclass1 this_ INNER JOIN base this_1_
ON this_.base_id = this_1_.base_id
ORDER BY this_.NAME ASC
And the error:
Code:
Caused by: java.sql.SQLException: ORA-00904: "THIS_"."BASE_ID": invalid identifier
The query is wrong; the first field in the SELECT ought to be "this_.sub_id", and the left side of the ON ought to be "this_.sub_id" also.
Any ideas?