diff --git a/reference/en/modules/basic_mapping.xml b/reference/en/modules/basic_mapping.xml index 2792c9ef2e..e06d139697 100644 --- a/reference/en/modules/basic_mapping.xml +++ b/reference/en/modules/basic_mapping.xml @@ -372,9 +372,10 @@ entity-name (optional): Hibernate3 allows a class to be mapped multiple times (to different tables, potentially), and allows entity mappings that - are represented by Maps or XML at the java level. In these cases, you should + are represented by Maps or XML at the Java level. In these cases, you should provide an explicit arbitrary name for the entity. See - for more information. + and + for more information. diff --git a/reference/en/modules/configuration.xml b/reference/en/modules/configuration.xml index 3ed51faa23..ea8f26a5a1 100644 --- a/reference/en/modules/configuration.xml +++ b/reference/en/modules/configuration.xml @@ -377,7 +377,7 @@ hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect]]> the other techniques described above. - +
Hibernate Configuration Properties @@ -482,6 +482,19 @@ hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect]]> + + + hibernate.default_entity_mode + + + Set a default mode for entity representation for all sessions + opened from this SessionFactory + + dynamic-map, dom4j, + pojo + + + hibernate.order_updates diff --git a/reference/en/modules/persistent_classes.xml b/reference/en/modules/persistent_classes.xml index 5df3b6e9ed..bb7602d0f4 100644 --- a/reference/en/modules/persistent_classes.xml +++ b/reference/en/modules/persistent_classes.xml @@ -309,18 +309,38 @@ public class DomesticCat extends Cat { - - Dynamic models + + Dynamic modelss - Hibernate also supports dynamic domain models, using Maps of - Maps. With this approach, you don't write persistent classes, - a Hibernate mapping file for each "entity" is sufficient: + Note that the following features are currently considered + experimental and may change in the near future. + + + + Persistent entities don't necessarily have to be represented as POJO classes + or as JavaBean objects at runtime. Hibernate also supports dynamic models + (using Maps of Maps at runtime) and the + representation of entities as DOM4J trees. With this approach, you don't + write persistent classes, only mapping files. + + + + By default, Hibernate works in normal POJO mode. You may set a default entity + representation mode for a particular SessionFactory using the + default_entity_mode configuration option (see + . + + + + The following examples demonstrates the representation using Maps. + First, in the mapping file, an entity-name has to be declared + instead of (or in addition to) a class name: - + - + - - - + + @@ -353,23 +373,38 @@ public class DomesticCat extends Cat { ]]> - At runtime, you just instantiate HashMaps and use - the Hibernate entity name to refer to a particular type: + + Note that even though associations are declared using target class names, + the target type of an associations may also be a dynamic entity instead + of a POJO. + + + + After setting the default entity mode to dynamic-map + for the SessionFactory, we can at runtime work with + Maps of Maps: @@ -380,6 +415,40 @@ s.close();]]> allowing to add a proper domain model implementation on top later on. + + Entity representation modes can also be set on a per Session + basis: + + + + + + + Please note that the call to getSession() using an + EntityMode is on the Session API, not the + SessionFactory. That way, the new Session + shares the underlying JDBC connection, transaction, and other context + information. This means you don't have tocall flush() + and close() on the secondary Session, and + also leave the transaction and connection handling to the primary unit of work. + + + + More information about the XML representation capabilities can be found + in . + + diff --git a/reference/en/modules/xml.xml b/reference/en/modules/xml.xml index fd1508458b..a60c9a83a7 100755 --- a/reference/en/modules/xml.xml +++ b/reference/en/modules/xml.xml @@ -1,42 +1,45 @@ - XML Mapping + + Note that this is an experimental feature in Hibernate 3.0 and is under + extremely active development. + + Working with XML data + Hibernate lets you work with persistent XML data in much the same way you work with persistent POJOs. A parsed XML tree can be thought of - as just another way to represent the relational data at the object level. + as just another way to represent the relational data at the object level, + instead of POJOs. + + + Hibernate supports dom4j as API for manipulating XML trees. You can write queries that retrieve dom4j trees from the database and have any modification you make to the tree automatically synchronized to the database. You can even take an XML document, parse it using dom4j, and write it to the database with any of Hibernate's basic operations: persist(), saveOrUpdate(), merge(), delete(), replicate() - (merge is not yet supported in Hibernate 3.0rc1). + (merging is not yet supported). - + This feature has many applications including data import/export, externalization of entity data via JMS or SOAP and XSLT-based reporting. - An single mapping may be used to simultaneously map properties of a class + A single mapping may be used to simultaneously map properties of a class and nodes of an XML document to the database, or, if there is no class to map, it may be used to map just the XML. - - - Note that this is an experimental feature in Hibernate 3.0 and is under - extremely active development. - - - - + Specifying XML and class mapping together + Here is an example of mapping a POJO and XML simultaneously: @@ -64,7 +67,8 @@ - Specifying just an XML mapping + Specifying only an XML mapping + Here is an example where there is no POJO class: @@ -94,19 +98,21 @@ ]]> - This mapping will let us access the data as a dom4j tree, or as a graph of + This mapping allows you to access the data as a dom4j tree, or as a graph of property name/value pairs (java Maps). The property names are purely logical constructs that may be referred to in HQL queries. + XML mapping metadata + Many Hibernate mapping elements accept the node attribute. - This let's us specify the name of an XML attribute or element that holds the + This let's you specify the name of an XML attribute or element that holds the property or entity data. The format of the node attribute must be one of the following: @@ -141,7 +147,7 @@ You should be careful not to leave embed-xml="true" for - too many associations, since XMl does not deal well with circularity! + too many associations, since XML does not deal well with circularity! ]]> - If we set embed-xml="true" on the <one-to-many> + If you set embed-xml="true" on the <one-to-many> mapping, the data might look more like this: @@ -230,14 +236,14 @@ Manipulating XML data - Now that we have mapped our entities to XML, we want to be able to read and - update XML documents in our application. We do this by obtaining a dom4j session: + Let's rearead and update XML documents in the application. We do this by + obtaining a dom4j session: