The code attached to this page is not working (as at 14 Jun 2004). Help is needed!
This page CformsHibernateAndFlow was developed from the original at WoodyHibernateAndFlow by Hugo Burm. Modifications have been made to adapt it to a subset of the CForms sample, shipped with Cocoon 2.1.5, and available in the samples/block/forms section.
Read UsingHibernateToMakeYourJavaBeansPersistent to perform the integration of Hibernate with Cocoon. Run the test sample to see that Hibernate is working properly.
Copy the contents of the hib path (in the zip file, attached to this page), into the WEB-INF/classes/hib folder under your Cocoon directory.
Copy the contents of form2bean2hib path (in the zip file, attached to this page), into a form2bean2hib folder under your Cocoon directory
Add the following line into your cocoon.xconf (this adds the Avalon component that creates the Hibernate session):
<component role="hib.PersistenceFactory" class="hib.HibernateFactory"/>
Create the table in your mysql database with the mysql.sql script (in the zip file, attached to this page).
Copy the hibernate.properties file (in the zip file, attached to this page) into the WEB-INF/classes folder under Cocoon. Edit the file to specify the appropriate login credentials for your database. Note: Hibernate has support for many different databases. Change the SQL dialect in hibernate.properties and edit the above script if you don't use mysql but something else.
Restart Tomcat. Near the end of the debug info in the console output (stdout.log in the Tomcat logs directory), there should be a line reading Hibernate initialize called. If you don't see this line, one of the points above went wrong.
Try http://.../form2bean2hib/ (where "..." is the path to your application under Cocoon).
The CForms Java beans Contact, Sex, and Form2Bean are not modified.
The sitemap of the CForms example is not modified.
Two classes are added - the interface of an Avalon component PersistenceFactory and its implementation HibernateFactory). This component creates the Hibernate session.
The flowscript binding_example.js is changed. The function form2bean tries to load the Form2Bean object from disk with a hard-coded email address as the key. If it fails, it creates a new instance and saves it to disk.
The real beef is in the file WEB-INF\classes\hib\Form2Bean.hbm.xml. This configuration file tells Hibernate how to do the real work: hide all details about the one-to-many relationship (contacts that are added to the bean) for the developer. When you try the example and look into the database, you can see that contacts are added with an unique key that is generated by Hibernate (the id field; don't edit it, as the Woody intructions tell you!) and a foreign key (the email address). In a real-world application, you almost always will need the lazy and inverse attributes (see Hibernate docs for explanation). In this case, the aim was to stay as close as possible to the original classes of the CForms sample.