休眠删除:SQLGrammarException 意外的标记:CROSS
Hibernate delete: SQLGrammarException Unexpected token: CROSS
我有 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。
有人知道我能做什么吗?
一种解决方案是重写查询。
您可以通过编写 SQL 查询来获取您需要删除的 ID,从而避免 eb.entityA 和 eb.entityC 之间的交叉连接。然后对每个 id 调用 HQL delete。
我有 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。 有人知道我能做什么吗?
一种解决方案是重写查询。
您可以通过编写 SQL 查询来获取您需要删除的 ID,从而避免 eb.entityA 和 eb.entityC 之间的交叉连接。然后对每个 id 调用 HQL delete。