我有3个实体:
实体A,实体B,实体C.
public class Entity_A {
public List<Entity_B> entBList;
Some other objects...
@OneToMany(mappedBy="entityA", cascade = {CascadeType.ALL}, fetch = FetchType.EAGER, orphanRemoval=true)
@Fetch(value = FetchMode.SUBSELECT)
public List<GebruikerKind> getEntBList() {
return entBList;
}
}
public class Entity_B {
public Entity_A entityA;
public Entity_C entityC;
Some other objects...
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "COLUMNJOINNAME")
public Entity_A getEntityA() {
return entityA;
}
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "OTHERCOLUMNJOINNAME)
public Entity_C getEntityC() {
return entityC;
}
}
public class Entity_C {
public List<Entity_B> entBList;
Some other objects...
@OneToMany(mappedBy="entityC", cascade = {CascadeType.ALL}, fetch = FetchType.EAGER, orphanRemoval=true)
@Fetch(value = FetchMode.SUBSELECT)
public List<GebruikerKind> getEntBList() {
return entBList;
}
}
注意:所有的setter都可用,并且还有很多其他对象可用:)。 据我所知,我的配置很好.. 我试图删除Entity_B:
Query query = getCurrentSession().createQuery(
"delete from " + Entity_B.class.getName() + " eb " +
" where eb.entityA.someField = :someField and eb.entityC.someOtherField = :someOtherField");
query.setString("someField", someId);
query.setString("someOtherField", someOtherId);
return query.executeUpdate();
天堂里的烦恼:
Hibernate抛出了这个SQLGrammarException:意外的令牌:Cross。 谁知道我能做什么?
答案 0 :(得分:1)
一种解决方案是重写查询。
您可以通过编写SQL查询来获取需要删除的ID来避免eb.entityA和eb.entityC之间的交叉连接。然后在每个ID上调用HQL删除。