Reinhard Poetz wrote:

For a quick hack I wrote a singleton (simple Java class) that manages the Hibernate SessionFactory. As it is only a Cocoon/Hibernate-demo I haven't thought much about it, but if I use Hibernate in production, I would write a SingleThreaded Avalon component. I would do it because Cocoon is based on Avalon, but are there any technical reasons?
This is not an answer for your question but I recommend you do not use Hibernate in Cocoon directly. For all database applications I use following trio: Cocoon + Spring + Hibernate.

Using spring as your "hibernate manager" gives you following advantages:
- spring manages hibernate session in a transparent way
- supports open session in view pattern
- you can use declarative transaction management
- supports DAO pattern (HibernateDaoSupport class)
- if for some reasons Hibernate can't handle something (or is not that performant as you'd wish it to) you can create a dao that uses jdbc. The trick is that although jdbc dao gets the connection from datasource in fact spring will pass the same connection that was used for hibernate interaction. Reused connection means you keep everything in a single transaction!
- the code gets much shorter and cleaner as the exceptions are manager by spring itself and coverted to runtime exceptions.
- testing your hibernate DAOs/services will be a lot easier.


just my 2c.

--
Leszek Gawron                                      [EMAIL PROTECTED]
Project Manager                                    MobileBox sp. z o.o.
+48 (61) 855 06 67                              http://www.mobilebox.pl
mobile: +48 (501) 720 812                       fax: +48 (61) 853 29 65

Reply via email to