Записи дочерней таблицы в спящем режиме не удаляются
У меня есть две таблицы с родительскими и дочерними отношениями, как показано ниже:
Parent Table:
@Entity
@Table(name = "frontend.rdp_strategy", uniqueConstraints = {@UniqueConstraint(columnNames = {"name", "datatype","source"})})
public class FrontRdpStrategy implements java.io.Serializable {
@Id
// @GeneratedValue(generator="optimized-sequence")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
private String name;
private String datatype;
private String source;
@OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER, mappedBy="frontRdpStrategy")
private Set<RdpStrategySequence> rdpStrategySequences = new HashSet<RdpStrategySequence>();
Child Table:
@Entity
@SuppressWarnings("serial")
@Table(name = "frontend.rdp_strategy_sequence")
public class RdpStrategySequence implements java.io.Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
// @GeneratedValue(generator="optimized-sequence")
private long id;
@ManyToOne(cascade = {CascadeType.ALL},fetch=FetchType.EAGER)
@JoinColumn(name = "rdp_strategy_id", nullable = false)
private FrontRdpStrategy frontRdpStrategy;
@ManyToOne( fetch=FetchType.EAGER)
@JoinColumn(name = "rdp_strategy_condition_id", nullable = false)
private RdpStrategyCondition rdpStrategyCondition;
Здесь CascadeType - это javax.persistence.CascadeType. Теперь я пытаюсь удалить только записи дочерней таблицы для определенного идентификатора родительской таблицы в дочерней таблице, используя запрос ниже:
session.createQuery("delete from frontend.rdp_strategy_sequence m where m.rdp_strategy_id = :id").setLong("id", id).executeUpdate();
Но я получаю следующее исключение:
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: frontend.rdp_strategy_sequence is not mapped [delete from frontend.rdp_strategy_sequence m where m.rdp_strategy_id = :id]
at org.hibernate.hql.internal.ast.QuerySyntaxException.generateQueryException(QuerySyntaxException.java:96)
at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:120)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:234)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:126)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:88)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:190)
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236)
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1800)
at frontend.guifx.dao.frontend.FrontendGUIFxDao.deleteSequenceForRdp(FrontendGUIFxDao.java:111)
at frontend.guifx.controller.EditRdpStrategyController.saveRdpStrategy(EditRdpStrategyController.java:637)
... 60 more
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: frontend.rdp_strategy_sequence is not mapped
at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:189)
at org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:109)
at org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:95)
at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:331)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3633)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3522)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:706)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.deleteStatement(HqlSqlBaseWalker.java:435)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:263)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:278)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:206)
... 69 more
Кинлды, посоветуйте же, где я делаю не так?
1 ответ
Вы должны использовать имя сущности, например так:
session.createQuery("delete from RdpStrategySequence m where m.id = :id").setLong("id", id).executeUpdate();