Quote:
1. Is there any difference between using the JDBC Connection provided by Hibernate and getting my own Connection through JNDI? Inside a stateless session bean method, I am using Hibernate Session to do some database operations (updates). For operations that cannot be performed by Hibernate (like complex native sqls), I would mix JDBC in the code. Not sure where I am heading to? Especially I am concerned with the Hibernate 1st level cache.
2. Is it possible to wrap the JDBC returned result into Hibernate objects?
1- why don't you get jdbc connexion from hibernate session ?
You can perfectly use jdbc code.
I advise you to isolate all hibernate & jdbc code inside a DAO layer.
If you mix hibernate & jdbc inside a use case, be sure to flush & clear your hibernate before coding in jdbc.
Now if you use hibernate in one use case, and jdbc in another and you follow the best practices (threadlocal pattern + 1 session per httpRequest), you don't have to worry about the 1st level cache.
If you use second level cache, all classes mapped to tables you'll will hit in pure jdbc shouldn't be cached (i'm talking about second level cache).
2- in this case use hibernate, search for sqlQuery examples, i'm pretty sure you can use it.