开发者

Hibernate: UPDATE with a user-provided SQL code

开发者 https://www.devze.com 2023-03-15 14:53 出处:网络
I\'ve been reading the documentation, but I couldn\'t find any information about it. Is it possible to have Hibernate send user-provided SQL queries in order to UPDATE or to INSERT an object in the d

I've been reading the documentation, but I couldn't find any information about it.

Is it possible to have Hibernate send user-provided SQL queries in order to UPDATE or to INSERT an object in the database?

In other words, is it possible to have session.saveOrUpdate( myObject ); , which generates update mySchema.myObject set field1=?, f开发者_如何学Cield2=?, field3=? where unique_key=? to be replaced with a manual query from a user-provided String?


This is well described in the reference documentation. There are caveats, though : the session and the second-level cache aren't aware of the changes made to the entities, the version field is not updated, etc.

And if HQL is still not sufficient, you may always fall back to SQL queries.

0

精彩评论

暂无评论...
验证码 换一张
取 消