Return-Path: Delivered-To: apmail-cocoon-dev-archive@www.apache.org Received: (qmail 56147 invoked from network); 12 Dec 2004 11:10:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 12 Dec 2004 11:10:05 -0000 Received: (qmail 4022 invoked by uid 500); 12 Dec 2004 11:10:01 -0000 Delivered-To: apmail-cocoon-dev-archive@cocoon.apache.org Received: (qmail 3948 invoked by uid 500); 12 Dec 2004 11:10:00 -0000 Mailing-List: contact dev-help@cocoon.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: dev@cocoon.apache.org Delivered-To: mailing list dev@cocoon.apache.org Received: (qmail 3926 invoked by uid 99); 12 Dec 2004 11:10:00 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: neutral (hermes.apache.org: local policy) Received: from viefep13-int.chello.at (HELO viefep13-int.chello.at) (213.46.255.15) by apache.org (qpsmtpd/0.28) with ESMTP; Sun, 12 Dec 2004 03:09:59 -0800 Received: from [192.168.1.31] (really [62.178.239.20]) by viefep13-int.chello.at (InterMail vM.6.01.03.05 201-2131-111-107-20040910) with ESMTP id <20041212110955.HUB27023.viefep13-int.chello.at@[192.168.1.31]> for ; Sun, 12 Dec 2004 12:09:55 +0100 Message-ID: <41BC26FD.20702@apache.org> Date: Sun, 12 Dec 2004 12:09:49 +0100 From: Reinhard Poetz User-Agent: Mozilla Thunderbird 0.9 (Windows/20041103) X-Accept-Language: en-us, en MIME-Version: 1.0 To: dev@cocoon.apache.org Subject: Re: [SOT] SingleThreaded components vs. Singletons References: <41BBF590.3090906@apache.org> <41BC1EA0.5000100@mobilebox.pl> In-Reply-To: <41BC1EA0.5000100@mobilebox.pl> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Leszek Gawron wrote: > 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. Thank you very much! I understand all those advantages. However using Spring introduces another layer of complexity. It's always a question of *who* is developing the application. The target group of the demo, that I was speaking of, has very little experience with web development and *never* used Cocoon at all. I'm going to focus on introducing the concepts of pipelines and flow, Spring would be too much ATM. At least I will prepare one silde giving an outlook on what could be improved in the future :-) -- Reinhard