Hibernate version: any / none yet / current :-)
Code between sessionFactory.openSession() and session.close(): (yes, that's what I need to figure out... )
Name and version of the database you are using: MySQL 4 / Oracle
Hi everybody,
I've just started evaluating Hibernate, done some tutorials, read some documentation and everything seems to work just fine so far :-))).
However, I have one problem I couldn't find an answer to and I would guess I'm not the only one with this "issue"?!
I need to extend / refactor an existing server application, which currently uses a DAO pattern. I want to use Hibernate for all new entities, but need a way for it to "co-exist" with the current DAOs. Then, in due time and one by one, I hope I can convert the DAOs to Hibernate.
The main "issue" I see is one (JDBC-)transaction which is supposed to modify "Hibernate entities" as well as "old" "DAO-entities". How can I do this?
The Hibernate Reference Guide wrote:
You may also use Hibernate's direct SQL query feature or get a plain JDBC connection from a Session in rare cases.
How do I do that? I could't find it in the documentation or the "code completion" for "session".
And is this the "proper" way of doing things? Will it work if I get a session, let Hibernate save a few objects, then execute 2 SQL statements via JDBC, let Hibernate update an Object (NOT the same classes, no association, each table will be accessed only by Hibernate OR DAOs).
I know this is not "perfect" and will only be needed for a "transition" period...
The documentation also says I can execute "plain SQL" statements and I couldn't find that either. I need to execute PreparedStatements from my code for entities which are not managed by Hibernate. Is that possible?
I've also started experimenting with a ConnectionProvider and actually got it to work very quickly (very good API *happy*). I could imagine a setup where my SessionFactory stores a JDBC connection along with the session in my ThreadLocal. When the session requests the connection, I see if I already have one for that thread (for the DAOs) and just pass the same connection. But how do I handle commit/rollback? I guess two commits are no problem, but what if Hibernate wants to commit and the DAOs want to roll back?
"Trying" all this in code would be a *LOT* of work (for me at least...), so I would really appreciate some hints from some Hibernate experts :-)))
Thanks in advance,
Holger