I need to execute some SQL queries that modifies the data used by hibernate (DML operations). I have the following restriction: the application running as a standalone java application and it's using an embedded Apache Derby database, it allows only one connection to database, so I can't open another connection, I have to use the same JDBC connection that hibernate is using.
I also can't close the session and open it again, because the session takes about 60 seconds to start according to the application developer (another company)
I know there is a connection method in org.hibernate.Session from where I can get the underlying JDBC connection, but I'm not sure that my modifications in the database would be in conflict with some buffer or cache in memory.
I want to use the following code:
Code:
session.clear();
session.flush();
java.sql.Connection con = session.connection();
// use the connection to perform DML operations
There is no con.close() because the connection was created by Hibernate.
Are flush() and clear() method calls enough to be sure that nothing will go wrong between hibernate and the database?