From f1c2817dfe54b54b29b07c44df7c90715a4e0934 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Wed, 10 Aug 2005 04:54:55 +0000 Subject: [PATCH] doc new 3.1 stuff git-svn-id: https://svn.jboss.org/repos/hibernate/trunk/Hibernate3/doc@7792 1b8cb986-b30d-0410-93ca-fae66ebed9b2 --- reference/en/modules/events.xml | 58 ++++++++++------ reference/en/modules/performance.xml | 31 +++++++-- reference/en/modules/session_api.xml | 3 +- reference/en/modules/transactions.xml | 96 ++++++++++++++++++++++++++- 4 files changed, 159 insertions(+), 29 deletions(-) diff --git a/reference/en/modules/events.xml b/reference/en/modules/events.xml index 20e2b8882d..a3383efbc1 100755 --- a/reference/en/modules/events.xml +++ b/reference/en/modules/events.xml @@ -7,7 +7,7 @@ functionality, and extension of Hibernate functionality. - + Interceptors @@ -20,6 +20,11 @@ lastUpdateTimestamp property when an Auditable is updated. + + + You may either implement Interceptor directly or (better) extend + EmptyInterceptor. + @@ -108,14 +116,15 @@ public class AuditInterceptor implements Interceptor, Serializable { - You may also set an interceptor on a global level, using the Configuration: + You may also set an interceptor on a global level, using the Configuration. + In this case, the interceptor must be threadsafe. - + Event system @@ -154,26 +163,28 @@ public class AuditInterceptor implements Interceptor, Serializable { example of a custom load event listener: - - You also need a configuration entry telling Hibernate to use the listener instead - of the default listener: + You also need a configuration entry telling Hibernate to use the listener in addition + to the default listener: ... - + + + + ]]> @@ -182,7 +193,8 @@ public class AuditInterceptor implements Interceptor, Serializable { +LoadEventListener[] stack = { new MyLoadListener(), new DefaultLoadEventListener() }; +cfg.EventListeners().setLoadEventListeners(stack);]]> Listeners registered declaratively cannot share instances. If the same class name is @@ -201,7 +213,7 @@ cfg.getSessionEventListenerConfig().setLoadEventListener( new MyLoadListener() ) - + Hibernate declarative security Usually, declarative security in Hibernate applications is managed in a session facade @@ -219,6 +231,12 @@ cfg.getSessionEventListenerConfig().setLoadEventListener( new MyLoadListener() ) ]]> + + Note that <listener type="..." class="..."/> is just a shorthand + for <event type="..."><listener class="..."/></event> + when there is exactly one listener for a particular event type. + + Next, still in hibernate.cfg.xml, bind the permissions to roles: diff --git a/reference/en/modules/performance.xml b/reference/en/modules/performance.xml index 8f6bfe0a51..f343185359 100644 --- a/reference/en/modules/performance.xml +++ b/reference/en/modules/performance.xml @@ -702,7 +702,7 @@ Cat fritz = (Cat) iter.next();]]> - + Cache mappings @@ -713,20 +713,39 @@ Cat fritz = (Cat) iter.next();]]> + + ]]> - usage specifies the caching strategy: + usage (required) specifies the caching strategy: transactional, read-write, nonstrict-read-write or read-only + + + region (optional, defaults to the class or + collection role name) specifies the name of the second level cache + region + + + + + include (optional, defaults to all) + non-lazy specifies that properties of the entity mapped + with lazy="true" may not be cached when attribute-level + lazy fetching is enabled + + @@ -1156,10 +1175,10 @@ hibernate.cache.use_structured_entries true]]> +Child c = new Child(); +c.setParent(p); +p.getChildren().add(c); //no need to fetch the collection! +sess.flush();]]> diff --git a/reference/en/modules/session_api.xml b/reference/en/modules/session_api.xml index ebfbcdbfd8..fe96d1de21 100644 --- a/reference/en/modules/session_api.xml +++ b/reference/en/modules/session_api.xml @@ -1022,7 +1022,8 @@ sess.find("from Cat as cat left outer join cat.kittens kitten"); // change to izi is not flushed! ... -tx.commit(); // flush occurs]]> +tx.commit(); // flush occurs +sess.close();]]> During flush, an exception might occur (e.g. if a DML operation violates a constraint). diff --git a/reference/en/modules/transactions.xml b/reference/en/modules/transactions.xml index 922b04f945..6203d70fc1 100644 --- a/reference/en/modules/transactions.xml +++ b/reference/en/modules/transactions.xml @@ -380,7 +380,7 @@ idiom looks like this: - + + + Or even like this: + + + @@ -461,6 +485,30 @@ catch (RuntimeException e) { if (tx != null) tx.rollback(); throw e; // or display error message } +finally { + sess.close(); +}]]> + + + Or: + + + @@ -601,9 +649,53 @@ Session sess = factory.getCurrentSession(); - + + Transaction timeout + + + One extremely important feature provided by a managed environment like EJB + that is never provided for non-managed code is transaction timeout. Transaction + timeouts ensure that no misbehaving transaction can indefinitely tie up + resources while returning no response to the user. Outside a managed (JTA) + environment, Hibernate cannot fully provide this functionality. However, + Hibernate can at least control data access operations, ensuring that database + level deadlocks and queries with huge result sets are limited by a defined + timeout. In a managed environment, Hibernate can delegate transaction timeout + to JTA. This functioanlity is abstracted by the Hibernate + Transaction object. + + + + + + Note that setTimeout() may not be called in a CMT bean, + where transaction timeouts must be defined declaratively. + + + +