Reputation: 2092
There are two entities:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class Person implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
...
}
@Entity
public class Man extends Person {
...
}
Trying to execute the following method:
@Test
public void clear(EntityManager em) {
EntityTransaction tx = em.getTransaction();
tx.begin();
System.out.println(em
.createQuery("delete from Man m where m.id > 14582647")
.executeUpdate());
tx.commit();
}
Get the error:
[ERROR] ORA-00918: column ambiguously defined
hibernate.show_sql shows sql-queries:
Hibernate: insert into HT_Man select man0_.id as id from Man man0_ inner join Person man0_1_ on man0_.id=man0_1_.id where id=14582647
Hibernate: delete from HT_Man
The error occurs in a place where id = 14582647 as there must be more than just id, and for example man0_.id. How to generate the correct sql-query?
Upvotes: 1
Views: 1553
Reputation: 3915
Add a @PrimaryKeyJoinColumn annotation on Man class:
@Entity
@PrimaryKeyJoinColumn(name = "<pk column name in Man table>")
public class Man extends Person {
...
}
Also, you should define a Discriminator column in Person and the @DiscriminatorValue in Man so that Hibernate can figure out which tables to join (when you introduce say a Woman table).
Upvotes: 1