Using SQLQuery.uniqueResult() to perform native SQL INSERTs and UPDATEs
I am using Hibernate in my project and there is a certain scenario where I want to use the uniqueResult() method on t开发者_如何学Pythonhe org.hibernate.SQLQuery class to perform native SQL INSERT and UPDATE operations.
I did try using the executeUpdate() method on the same class. But I get an error saying that they are used for HQL updates only.
Please advice if this is effective and reliable way of ensuring data being saved/updated in the database.
session.createSQLQuery()
is for querying, not manipulation. If you want to do raw SQL insert, use session.connection()
and straight JDBC code.
Not sure why you need this exactly but I'd also suggest to check 16.3. Custom SQL for create, update and delete.
精彩评论