|
From: Barthel S. (JIRA) <no...@at...> - 2006-02-22 19:32:50
|
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-870?page=comments#action_22291 ] Barthel Steckemetz commented on HHH-870: ---------------------------------------- The patch works for us. In addition SQL-Logging should be supported in NativeSQLQueryPlan e.g.like this: private String format(SessionImplementor session, String sql) { if ( session.getFactory().getSettings().isFormatSqlEnabled() ) { return new Formatter(sql).format(); } else { return sql; } } public int performExecuteUpdate(QueryParameters queryParameters, SessionImplementor session) throws HibernateException { if (log.isTraceEnabled()) { log.trace("executeUpdate: " + getSourceQuery()); queryParameters.traceParameters(session.getFactory()); } if ( session.getFactory().getSettings().isShowSqlEnabled() ) { System.out.println( "Hibernate: " + format(session, getSourceQuery()) ); } int result = 0; try { Connection connection = session.connection(); try { PreparedStatement ps = connection .prepareStatement(this.sourceQuery); try { Type[] types = queryParameters .getPositionalParameterTypes(); Object[] values = queryParameters .getPositionalParameterValues(); for (int i = 0; i < types.length; i++) { types[i].nullSafeSet(ps, values[i], i + 1, session); } result = ps.executeUpdate(); } finally { ps.close(); } } finally { connection.close(); } } catch (SQLException sqle) { throw JDBCExceptionHelper.convert(session.getFactory() .getSQLExceptionConverter(), sqle, "could not execute update query", this.sourceQuery); } return result; } > support SQL updates in named queries > ------------------------------------ > > Key: HHH-870 > URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-870 > Project: Hibernate3 > Type: New Feature > Components: core > Environment: Hibernate 3.0.5, SQL Server 2000 > Reporter: Nathan Moon > Priority: Minor > Attachments: patch.txt > > > currently attempting to execute a named <sql-query> that is an update statement throws java.lang.UnsupportedOperationException: Update queries only supported through HQL. > In order to execute sql updates, the Session.connection() must be used directly. > (see forum topic http://forum.hibernate.org/viewtopic.php?t=940281) > It would be very nice to be able to be able to externalize SQL update statements and be able to run them with Session.getNamedQuery(). -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |