• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can I do raw DML with Hibernate?  RSS feed

 
Chase Bonham
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I do raw DML with Hibernate?
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hibernate's JDBC Connection is available by calling Session.connection(). Once you have the connection you can run any sql you wish.
 
Chase Bonham
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any DML made on such a connection be made transactional with
the rest of hibernate calls.

tx = session.beginTransaction();
session.save(object);
session.getConnection.execute("update .....some dml");
tx.commit();
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use the JDBC connection directly it will bypass the Session of Hibernate, if you just want to run an SQL Statement you can create an SQLQuery object form the Session and still use the Session and Transaction demarcation.

Mark
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!