hib
path (in the zip file, attached to this page), into the WEB-INF/classes/hib
folder under your Cocoon directory.form2bean2hib
path (in the zip file, attached to this page), into a form2bean2hib
folder under your Cocoon directorycocoon.xconf
(this adds the Avalon component that creates the Hibernate session):<component role="hib.PersistenceFactory" class="hib.HibernateFactory"/> |
mysql.sql
script (in the zip file, attached to this page).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.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.http://.../form2bean2hib/
(where "..." is the path to your application under Cocoon).
PersistenceFactory
and its implementation HibernateFactory
). This component creates the Hibernate session.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.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.
Attachment: form2bean2hib.zip