tags:

views:

23

answers:

2

Hello!

I have a project running live for couple of years and it uses plain jdbc. Now I have to implement a small module for which I am considering hibernate. I configured hibernate(hibernate-cfg.xml) and its up n running.So I have DB properties defined in two places oracle-ds.xml and hibernate-cfg.xml 1.Is that OK to mix jdbc,hibernate in a single application, if not what are the issues? 2.Do I need to configure "connection pool" in hibernate configuration and also in oracle-ds.xml(JBOSS application server). 3.I thought of configuring hibernate using JNDI but that needs mbean, HAR thats extra work and this new module is going to be used rarely. OR Should I make it as an jboss service so that connection pooling is handled by container? 4.I can use plain jdbc but team wants to try hibernate and if everything works fine, we are looking into using hibernate full time for next project.

A: 

We've mixed the two in the same application with no problems. I set the server to manage the connection pool so they end up getting shared between the JDBC code and hibernate code.

One thing you do have to keep in mind is hibernate caches the data in memory, so if you change a hibernate table directly, the application will still keep seeing the old data that's in the cache. If you turn off the cache, it takes a big performance hit. It saves you coding but you lose a lot in flexibility. It's difficult to integrate with other applications through the database and do things like replication between sites.

JOTN
Thanks. Do you know how I let server manage the connection pool. Right now I defined "connection pool size" in both hibernate config and oracle-ds.xml files.
Tag
I got it. I used JNDI name from oracle-ds file and it worked. Thanks!
Tag
A: 

Is that OK to mix jdbc, hibernate in a single application, if not what are the issues?

It's doable but you need to take some precautions:

  • You can't easily mix JDBC handled POJOs in a graph of Hibernate handled objects (so try to use Hibernate for the deepest objects in a graph or for fully Hibernatized graphs).
  • I guess you have some concurrency mechanism, use the same for JDBC and Hibernate (i.e. increment the same version column from JDBC and Hibernate).
  • If you configure Hibernate to use the 2nd level cache, Hibernate won't be aware of changes made without using its API (so you might have to implement some evict mechanism).

Do I need to configure "connection pool" in hibernate configuration and also in oracle-ds.xml

I would configure Hibernate to use the app server connection pool (see the Hibernate Datasource Properties).

I thought of configuring hibernate using JNDI but that needs mbean, HAR thats extra work and this new module is going to be used rarely. OR Should I make it as an jboss service so that connection pooling is handled by container?

You don't need to use a JBoss service or to use a HAR to use connection pooliong, see the above link. And I wouldn't bother with that for now, this is very low priority stuff in my opinion. First, bootstrap a first prototype, see how it fit with your existing code, what needs to be changed, etc.

Pascal Thivent