aspose file tools
The moose likes Object Relational Mapping and the fly likes Can I do raw DML with Hibernate? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "Can I do raw DML with Hibernate?" Watch "Can I do raw DML with Hibernate?" New topic
Author

Can I do raw DML with Hibernate?

Chase Bonham
Ranch Hand

Joined: Jul 15, 2006
Posts: 50
Can I do raw DML with Hibernate?
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
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

Joined: Jul 15, 2006
Posts: 50
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

Joined: Feb 05, 2001
Posts: 16622

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
 
subject: Can I do raw DML with Hibernate?
 
Threads others viewed
Hibernate - Retriving Custom Query Result
BMT Rollback Issue
Is it possible or not?
serializable object
Viewing # of rows updated by Hibernate DML
developer file tools