【发布时间】:2017-07-29 17:15:47
【问题描述】:
我正在尝试在休眠会话中运行本机 SQL 删除,但我收到一个异常,抱怨表别名。如果我在 SQL 客户端中运行 sql 查询,那么它工作正常。
String sql = 'delete c from child c join parent p on c.parent_id=p.id where p.some_id = :someId'
SQLQuery deleteQuery = sessionFactory.currentSession.createSQLQuery(sql)
deleteQuery.setParameter( 'someId', some.id.longValue() )
deleteQuery.executeUpdate()
在我的单元测试中抛出异常:
[main] ERROR util.JDBCExceptionReporter - Table "C" not found; SQL statement:
delete c from child c join parent p on c.parent_id=p.id where p.some_id = ? [42102-164]
org.hibernate.exception.SQLGrammarException: could not execute native bulk manipulation query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.engine.query.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:219)
at org.hibernate.impl.SessionImpl.executeNativeUpdate(SessionImpl.java:1310)
at org.hibernate.impl.SQLQueryImpl.executeUpdate(SQLQueryImpl.java:396)
at org.hibernate.Query$executeUpdate.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
关于为什么这不能通过休眠工作的任何建议?
【问题讨论】: