mysql - Hibernate native sql table not found error -
i'm trying run native sql delete in hibernate session, exception complaining table alias. if run sql query in sql client, works fine.
string sql = 'delete c child c join parent p on c.parent_id=p.id p.some_id = :someid' sqlquery deletequery = sessionfactory.currentsession.createsqlquery(sql) deletequery.setparameter( 'someid', some.id.longvalue() ) deletequery.executeupdate()
exception thrown in unit test:
[main] error util.jdbcexceptionreporter - table "c" not found; sql statement: delete c child c join parent p on c.parent_id=p.id p.some_id = ? [42102-164] org.hibernate.exception.sqlgrammarexception: not execute native bulk manipulation query @ org.hibernate.exception.sqlstateconverter.convert(sqlstateconverter.java:92) @ org.hibernate.exception.jdbcexceptionhelper.convert(jdbcexceptionhelper.java:66) @ org.hibernate.engine.query.nativesqlqueryplan.performexecuteupdate(nativesqlqueryplan.java:219) @ org.hibernate.impl.sessionimpl.executenativeupdate(sessionimpl.java:1310) @ org.hibernate.impl.sqlqueryimpl.executeupdate(sqlqueryimpl.java:396) @ org.hibernate.query$executeupdate.call(unknown source) @ org.codehaus.groovy.runtime.callsite.callsitearray.defaultcall(callsitearray.java:45) @ org.codehaus.groovy.runtime.callsite.abstractcallsite.call(abstractcallsite.java:108) @ org.codehaus.groovy.runtime.callsite.abstractcallsite.call(abstractcallsite.java:112)
any suggestions on why doesn't work through hibernate?
(edited)
using names of tables better.
string sql = 'delete child child inner join parent on child.parent_id = parent.id parent.some_id = :someid';
add
this example code (my) adapted you:
... public boolean eliminar( child some_id ) { boolean result = false; session session = null; transaction rs = null; try { session = sessionfactory.opensession(); rs = session.begintransaction(); rs.settimeout(5); string query_string = "delete child child inner join parent on child.parent_id = parent.id parent.some_id = :someid"; query_string.setparameter( 'someid', some_id ); query q = session.createquery(query_string); q.executeupdate(); rs.commit(); result = true; } catch(runtimeexception e) { try { rs.rollback(); } catch(runtimeexception rbe) { system.out.println(rbe.getmessage()); } system.out.println(e.getmessage()); } { session.close(); } return result; } ...
Comments
Post a Comment