Date: 2004-11-16T22:42:05
   Editor: DerekLastname <[EMAIL PROTECTED]>
   Wiki: Cocoon Wiki
   Page: GettingStartedWithCocoonAndHibernate
   URL: http://wiki.apache.org/cocoon/GettingStartedWithCocoonAndHibernate

   tidied up text and headers - inserted more "place holders"

Change Log:

------------------------------------------------------------------------------
@@ -7,12 +7,12 @@
 
 = What must you know before you start? =
 
-''outline skills and depth of knowledge required''
+''Skills and depth of knowledge required''
   *  You need to be proficient in Java, have basic SQL knowledge in case you 
want to do troubleshooting. 
   *  You should now how to translate your application domain into a solid 
database model.
   *  Understand the "lazy loading" concept that most O/R mapping tools use by 
default. This generally means that nothing is retrieved from the database until 
you really ask for it. [http://www.hibernate.org/162.html]. Also see below for 
notes on lazy collection initialization. 
 
-''outline skills and depth of knowledge that would be useful''
+''Skills and depth of knowledge that could be useful''
 
 ----
 
@@ -28,11 +28,19 @@
 
 == Random query monitoring tool ==
 
-It is useful to see what queries your mapping tool is actually generating 
under the hood. With hibernate you can configure this in the configuration 
file. Alternatively most databases also offer query logging.
+It is useful to see what queries your mapping tool is actually generating 
under the hood. With Hibernate you can configure this in the configuration 
file. This is done as follows:
+
+{{{
+Please fill me in!
+}}}
+
+Alternatively most databases also offer query logging. See, for example:
+
+* ''Please add links to on-line docs (e.g. for mySQL)''
 
 == Middlegen ==
 
-Middlegen extracts hibernate mapping files from your database. It also 
correctly generates the mapping relations between tables if you setup foreign 
key constraints. 
+[http://boss.bekk.no/boss/middlegen/ Middlegen] extracts Hibernate mapping 
files from your database. It also correctly generates the mapping relations 
between tables if you set up foreign key constraints. 
 
 It can be obtained from [http://boss.bekk.no/boss/middlegen/], check also 
[http://middlegen.codehaus.org/] or [http://www.hibernate.org/98.html] 
 
@@ -44,12 +52,23 @@
 
 = How to Install and Configure the Software =
 
-Hibernate can be deployed according to the installation procedure found at 
[http://www.hibernate.org/].  
+== Hibernate ==
+
+Hibernate itself can be deployed according to the installation procedure found 
at [http://www.hibernate.org/].  
+
+== Hibernate Under Cocoon ==
+
+If you want to set up Hibernate under Cocoon, it is recommended that you setup 
a servlet filter for handling the disposal of Hibernate sessions. This ensures 
that your Hibernate session sticks around until '''after''' your view was 
rendered. A brief summary of the steps is:
 
-  *  If you want to setup hibernate under Cocoon I recommend you setup a 
servlet filter for handling the disposal of hibernate sessions. This ensures 
that your hibernate session sticks around until *after* your view was rendered. 
This technique is described in more detail in the "Hibernate in Action" book 
([http://www.manning.com/bauer]). 
+1. 
+1.
+1.
 
+This technique is described in more detail in the "Hibernate in Action" book 
([http://www.manning.com/bauer]). 
 
-Other installation procedures needed before getting started are ...
+== Other Installation Procedures ==
+
+needed before getting started are ...
 
 ----
 
@@ -124,14 +143,12 @@
 === Lazy Collection Initialization ===
 
 Lazy Collection Initialization is an extremely important contribution to 
decent performance of your Hibernate application. 
-By Default, when fetching an object from the database, Hibernate makes sure 
that every other object reachable via getter methods is 
-also available. 
 
-Suppose you have an article object. Each article has a vector of related 
articles so users can comfortably browse to your 
-store. The following java snippet illustrates this: 
+By default, when fetching an object from the database, Hibernate makes sure 
that every other object reachable via getter methods is also available. 
 
-{{{
+Suppose you have an article object. Each article has a vector of related 
articles so users can comfortably browse to your store. The following java 
snippet illustrates this: 
 
+{{{
  import java.util.List
 
  public class Article{ 
@@ -144,7 +161,6 @@
       return relatedArticles;
    }
  } 
-
 }}}
 
 The corresponding fragment of your mapping file setup straight forward might 
look like this: 
@@ -174,30 +190,19 @@
 }}}
 
 
-Now suppose you have five Articles in your database, say A,B,C,D,E. A links to 
B and D while B links to C and D links to E.
-If you use hibebernate to fetch Article A from the database, it will also 
fetch ''all other Articles,'' since you could theoretically
-navigate to all of them using getter methods, i.e. you could reference Article 
E by typing 
-
+Now suppose you have five Articles in your database, say A,B,C,D,E. A links to 
B and D while B links to C and D links to E. If you use hibebernate to fetch 
Article A from the database, it will also fetch ''all other Articles,'' since 
you could theoretically navigate to all of them using getter methods, i.e. you 
could reference Article E by typing: 
+{{{
 Article E = A.getRelatedArticles().get(1).getRelatedArticles().get(0); 
+}}}
+This can be useful if you know that you are going to use all or most articles 
anyway. But in almost every case where you do not need to access your entire 
database at once (which is almost every use case I could imagine) it will be 
useless and lead to dramatic performance loss. 
 
-This can be useful if you know that you are going to use all or most articles 
anyway. But in almost every case where you do
-not need to access your entire database at once (which is almost every use 
case I could imagine) it will be useless and lead
-to dramatic performance loss. 
-
-The solution is called Lazy Collection Initialization. This Hibernate feature 
basically leaves all elements in Lists, Maps and other 
-collections uninitialized until the element is actually accessed via get() or 
similar  methods. To turn it on, simply set the attribute
-"lazy" of the respective collection to "true": 
+The solution is called Lazy Collection Initialization. This Hibernate feature 
basically leaves all elements in Lists, Maps and other collections 
uninitialized until the element is actually accessed via {{get()}} or similar  
methods. To turn it on, simply set the attribute "lazy" of the respective 
collection to "true": 
 
 {{{ <list name="relatedArticles" table="Article_Relations" lazy="true"> }}}
 
-If you, like me, programmed a whole webapp without knowing about this feature, 
try it out and see that it will work wonders on 
-overall performance :) Now, when fetching article A, it will only fetch 
article A. If, and only if, you acess article B via the
-relatedArticles List, it will connect to the DB again and fetch it 
dynamically. For this to work, ensure your Hibernate Session is left
-open until you have entirely finished working with your business objects.  
-
-You should decide carefully where to use lazy initialization and where not; it 
is not always beneficial, since sometimes you might have 
-a collection whose elements are almost always accessed. Query monitoring is 
useful to find out whether you have set up lazy initialization
-optimally. 
+If you, like me, programmed a whole webapp without knowing about this feature, 
try it out and see that it will work wonders on overall performance :) Now, 
when fetching article A, it will only fetch article A. If, and only if, you 
acess article B via the relatedArticles List, it will connect to the DB again 
and fetch it dynamically. For this to work, ensure your Hibernate Session is 
left open until you have entirely finished working with your business objects.  
+
+You should decide carefully where to use lazy initialization and where not; it 
is not always beneficial, since sometimes you might have a collection whose 
elements are almost always accessed. Query monitoring is useful to find out 
whether you have set up lazy initialization optimally. 
 
 === Query Caching ===