cocoon-docs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <>
Subject [Cocoon Wiki] Update of "CocoonAndHibernateTutorial" by JohannesTextor
Date Sun, 08 May 2005 22:08:42 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Cocoon Wiki" for change notification.

The following page has been changed by JohannesTextor:

  - COCOON-RELEASES: 2.1.5 2.1.6 2.1.7[[BR]]
  - DOCUMENT-STATUS: '''*draft*''' reviewed released[[BR]]
- '''WARNING:'''
- This way of integrating Cocoon and Hibernate is not exactly beautiful design. You might
want to take the 
- extra time and learn about the Spring framework, which offers a more sophisticated and elegant
- Search the cocoon-users mailing list to find out more about this. 
  === What you will get from this page ===
- This page proposes a way of integrating Hibernate into Cocoon. There are other, probably
better, ways to 
- accomplish this using additional frameworks like Spring or C3P0. However, I do believe that
the approach presented
- here can be useful for those who are just starting to use Hibernate and don't want to learn
yet another framework. 
+ This page proposes a very basic way of using Hibernate from your Cocoon application. This
is '''not''' an 
+ introduction to Hibernate or Cocoon itself. It just covers the specific issues of integration
+ between the two. 
- This is '''not''' an introduction to Hibernate or Cocoon itself. It just covers the specific
issues of integration
- between the two. 
+ The approach presented here is very simple in that it tries to use facilities already provided
+ Cocoon to perform database connection pooling. However, without using another framework
you will have
+ direct interaction between Hibernate and Cocoon, which means calling Hibernate from flowscript.
+ people don't want to do this and prefer to use the Spring framework for additional abstraction.
+ you are not sure if this approach is right for you, make sure you read the "Conceptual Overview"

+ section first. 
+ === Topics covered ===
  The two main problems you have when integrating Hibernate into Cocoon are the following:

@@ -58, +60 @@

  === Technical prerequisites ===
- A running cocoon installation. I tried this on Cocoon 2.1.6. It might work 
+ A running cocoon installation. I tried this on Cocoon 2.1.6 and Cocoon 2.1.7. 
- with earlier versions, although there will be problems with the CForms 
- Namespaces (earlier Woody). 
+ This is written for Hibernate v 2.1.X, but it also works with Hibernate 3.0.
+ When using Hibernate 3, you'll have to adjust the Hibernate package name,
+ which has changed from {{{net.sf.hibernate}}} to {{{org.hibernate}}}.
+ == Conceptual overview == 
+ The approach presented here is built to work with Cocoon and Hibernate alone, 
+ without any further frameworks. This creates a dependency between Cocoon and Hibernate since
+ you will need to manage Hibernate sessions from flow script. Creating such a dependency
+ is considered bad design by many people. For example, you might build a webshop which
+ stores articles in a database. Using Hibernate, you will be able to replace the database
+ without too much hassle (switching from MySQL to Oracle, for example), but it will still

+ be a database. When you want to manage your articles via a remote web service (or a flat
+ text file or whatever means of data storage), you'll have to rewrite your flowscript.
+ You can avoid this dependency by using an additional framework like Spring or Avalon which

+ supports the "Inversion of Control" and "Data Access Object" design patterns. This will
+ a cleaner and more modular designed web application. 
+ So before you begin, think if the approach presented here is right for you. I use it for
+ projects, when even a change in the underlying database is very unlikely, and I know the

+ customer will never switch to something else than a database for data storage. Moreover,
+ yet another framework - like Spring - to the mix, the learning curve for new developers
+ even steeper, and the resulting web application even larger, which is too costly for some

+ projects. 
+ However, if you have a larger application or want a clean implementation of the IOC and
+ design patterns, you should definately have a look at the Spring framework. The starting

+ point is the SpringPetstore at 
  == Setting up ==
@@ -84, +114 @@

  If you build cocoon exclude ojb block,this lib requried too:
  * odmg-3.0.jar
+ '''Hibernate 3 note''': Hibernate 3 also depends on "asm.jar" and "asm-attrs.jar". 
+ In Cocoon 2.1.7, these JARs are already provided in the WEB-INF/lib directory.
+ Unfortunately, the versions provided by Cocoon are not compatible with 
+ Hibernate 3. You'll have to delete those JARs and replace them with those shipped
+ with Hibernate, although i'm not sure if some parts of Cocoon rely on those 
+ particular versions (it works fine for me so far). 
  == Registering Hibernate with Avalon ==
  Now we will register Hibernate with Cocoon. If you are like me, you will 

View raw message