有两个实体:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class Person implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
...
}
@Entity
public class Man extends Person {
...
}
尝试执行以下方法:
@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();
}
得到错误:
[ERROR] ORA-00918: column ambiguously defined
hibernate.show_sql 显示 sql 查询:
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
错误发生在id = 14582647的地方,因为必须不止id,例如man0_.id。如何生成正确的 sql 查询?