1

I'm trying to add hibernate inheritance in existing structure. So, I need to add parent class which should generalize 3 entities. The problem is that now I need to get inherited fields in HQL from child. Something like this:

@Table(name="parents")
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public class Parent{
@Id
Long id;

 //additional code with protected getter and setter for id
}

@Table(name="childs")
@Entity
@PrimaryKeyJoinColumn(name="id")
public class Child extends Parent{

@Transient
public void setChildId(Long id){
super.setId(id);
}

@Transient
public Long getChildId(){
return super.getId();
}

Finaly with this code when I'm trying to execute HQL like

select c from Child c

I have an SQL error which says 'Unknown column childs.id'

What's wrong?

Anatoly
  • 1,551
  • 4
  • 21
  • 40
  • It works on my machine with hibernate 3. Is your `childs` table up to date? – dcernahoschi Sep 19 '12 at 18:15
  • So it's starts working when I change name of child id column to the same with parent. Is it really required? – Anatoly Sep 19 '12 at 18:57
  • 1
    The PrimaryKeyJoinColumn annotation says what the name of the ID column in the child table is. You explicitely configured it to be "id", as in the parent table. – JB Nizet Sep 19 '12 at 21:15

0 Answers0