You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Johannes Textor <jc...@gmx.de> on 2007/05/28 22:44:11 UTC

Cocoon / Hibernate revisited

Hello,

following an inspiring discussion with Fabrizio here on the User's list, 
I reworked the Cocoon and Hibernate tutorial and the underlying "glue" 
classes. The solution is now free of major architectural sins (as far as 
I can say) and allows a "clean" implementation of DAOs. No more opening 
sessions in flowscript (although you're free to do that if you want to). 
However, it is based on 2.1.10, as I'm still lacking the necessary 
knowledge to see if this is even necessary in 2.2.

I encourage everyone who uses the approach described in the old version 
to check out and test the new one, and bug me or this list with 
questions, problems and feedback :)

Cheers,
Johannes

P.S. Fabrizio, I think it should be easy to extend the presented pattern 
to your need of "long conversations". Would be nice to have that also ....


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Cocoon / Hibernate revisited

Posted by Johannes Textor <jc...@gmx.de>.
Hi Fabio,

Fabrizio Sitzia wrote:
> I've looked your page up in the Wiki - Wow! ("Einfach geil!")
Thanks for the props :) 
> As soon as I've got something I can trust in production, I'll write up
> the Wiki page describing it. I'll keep you posted.
>   
I'm looking forward to see that. Let's get rid of that rumour that 
Cocoon does not have good docs :)

Cheers,
Johannes


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Cocoon / Hibernate revisited

Posted by Fabrizio Sitzia <fa...@chem.lu>.
Hello Johannes,

> following an inspiring discussion with Fabrizio here on the User's list,
> I reworked the Cocoon and Hibernate tutorial and the underlying "glue"
> classes. The solution is now free of major architectural sins (as far as
> I can say) and allows a "clean" implementation of DAOs. No more opening
> sessions in flowscript (although you're free to do that if you want to).
> However, it is based on 2.1.10, as I'm still lacking the necessary
> knowledge to see if this is even necessary in 2.2.

I've looked your page up in the Wiki - Wow! ("Einfach geil!")

With that solution, you get rid of virtually all Hibernate / transaction
demarcation code in Flowscript.

How did you figure out that contextualize trick? (...guess I'll really
have to read the whole servlet spec someday ;-)


> I encourage everyone who uses the approach described in the old version
> to check out and test the new one, and bug me or this list with
> questions, problems and feedback :)
>
> Cheers,
> Johannes
>
> P.S. Fabrizio, I think it should be easy to extend the presented pattern
> to your need of "long conversations". Would be nice to have that also ....

Yes! I can already see this will turn into a lot cleaner solution than
the long conversation hack I previously described on this list.
That should appease the philosophers out there a bit :->

As soon as I've got something I can trust in production, I'll write up
the Wiki page describing it. I'll keep you posted.


Best regards,
Fabrizio


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Cocoon / Hibernate revisited

Posted by Baptiste Placé <bo...@free.fr>.
Johannes,

I have successfully refactored my code with your last update of the wiki 
article. Really clean and elegant.
I'm having one behavior I don't understand.
After starting tomcat, when I browse the homepage of my webapp, where no 
request are made on the database, I get this :

hibernate.OpenSessionInViewFilter - doFilter entered  (doFilter function 
called)
hibernate.PersistenceUtil - initializing scope  
(PersistenceUtil.initializeScope();)
hibernate.OpenSessionInViewFilter - persistenceFactory is not null   (if 
(persistenceFactory != null) is true)
hibernate.PersistenceUtil - Setting Session into Scope   
(PersistenceUtil.setHibernateSession(hs);)
hibernate.OpenSessionInViewFilter - doFilter entered  (doFilter function 
called)
...

This is spammed alot sometime. After about 20 times the page loads fine!
I have a slow computer but I doubt this is the reason.
Any idea on this issue ?

-Baptiste

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Cocoon / Hibernate revisited

Posted by Baptiste Placé <bo...@free.fr>.
Hi Tricia,

I would add to Johannes' answer those advantages of DAOs 
(http://java.sun.com/blueprints/patterns/DAO.html) :

The Data Access Object (or DAO) pattern:

    * separates a data resource's client interface from its data access
      mechanisms

    * adapts a specific data resource's access API to a generic client
      interface

The DAO pattern allows data access mechanisms to change independently of 
the code that uses the data.


Simply put, you can change your ORM API or change your DB without 
changing the methods used by the client. Only the code of the DAOs will 
be changed.

-Baptiste

Tricia Williams a écrit :
>    What is the advantage of using a DAO?
>
> Tricia

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Cocoon / Hibernate revisited

Posted by Johannes Textor <jc...@gmx.de>.
Hi Tricia,
>
>    What is the advantage of using a DAO?
I'm not sure if I am the right person to answer this question, but I'll 
give it a try. Quoting from Wikipedia at 
http://en.wikipedia.org/wiki/Data_Access_Object:

"Data Access Objects are a Core J2EE 
<http://en.wikipedia.org/wiki/Java_2_Platform%2C_Enterprise_Edition> 
Design Pattern and considered best practice. ... Data Access Objects can 
be used in Java 
<http://en.wikipedia.org/wiki/Java_%28programming_language%29> to 
insulate an application from the underlying Java persistence technology 
<http://en.wikipedia.org/wiki/Java_Persistence_API>,"

Anyway, my own view on this is that DAO, as any design patterns, is not 
useful per se, but only in certain situations. In fact, when I wrote my 
first applications using Cocoon and Hibernate, I simply called Hibernate 
directly from the flowscript layer.

However, as my applications got more and more complex, this turned out 
to be really messy. Doing all the data access on the flow layer had - 
for me - one big disadvantage: I had to do it in JavaScript, while all 
the classes I used and Hibernate itself were written in Java. The 
obvious mismatch between the two leads to a lot of issues, from proper 
exception handling to having to use weird syntax for "delete" methods 
(hs["delete"](obj), for example, since delete is a reserved keyword in 
JS). Furthermore, I simply missed my Eclipse and a strongly-typed 
language like Java seemed better suited for complex operations on 
business data. In the end, all the (luckily, few) applications I started 
like this have now grown into an ugly, unmanageable mess.

Personally, I think that flowscript is one of the main (and honestly, 
few) advantages Cocoon still has over other web application frameworks, 
but this strength only shows if you use it *just what it was designed 
for*, i.e. *control of page flow*. All non-trivial operations on 
bussiness data should, IMHO, *not* be done in flowscript. This means 
that you have to do them somewhere else - and here, the DAO pattern 
comes in handy. Using it, I have finally been able to code some 
applications in Cocoon and Hibernate I can actually be proud of.

I hope this gives you an Idea of why I'm recommending to use DAOs, but 
still, I do not think that this must necessarily be the right approach 
for everybody, just because it is "considered best practice".

Cheers,
Johannes






---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Cocoon / Hibernate revisited

Posted by Tricia Williams <pg...@student.cs.uwaterloo.ca>.
Hi Johannes,

    Thanks for your work on this!  I'm currently in the process of setting 
up hibernate 3 with cocoon 2.1.10 and have been back and forth between the 
the tutorials (simple application) at 
http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#tutorial-firstapp 
and http://wiki.apache.org/cocoon/CocoonAndHibernateTutorial.

    I can see that the first part of your re-write merges the setup that 
hibernate instructs (use of the hibernate.cfg.xml) and Util class to 
manage the session.  I haven't gone all the way through the tutorial but I 
thought I'd mention that there is an error in the _Installing the filter_ 
section.  the <filter-class>org.test.HibernateFilter</filter-class> should
become 
<filter-class>org.apache.cocoon.hibernate.OpenSessionInViewFilter</filter-class> 
in the new tutorial (I think).

    What is the advantage of using a DAO?

Tricia

On Mon, 28 May 2007, Johannes Textor wrote:

> Hello,
>
> following an inspiring discussion with Fabrizio here on the User's list, I 
> reworked the Cocoon and Hibernate tutorial and the underlying "glue" classes. 
> The solution is now free of major architectural sins (as far as I can say) 
> and allows a "clean" implementation of DAOs. No more opening sessions in 
> flowscript (although you're free to do that if you want to). However, it is 
> based on 2.1.10, as I'm still lacking the necessary knowledge to see if this 
> is even necessary in 2.2.
>
> I encourage everyone who uses the approach described in the old version to 
> check out and test the new one, and bug me or this list with questions, 
> problems and feedback :)
>
> Cheers,
> Johannes
>
> P.S. Fabrizio, I think it should be easy to extend the presented pattern to 
> your need of "long conversations". Would be nice to have that also ....
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org