HHH-4000 - Utlize jhighlight hooks for rendered syntax coloration of XML and Java based programlisting docbook elements

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@17916 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2009-11-04 23:32:27 +00:00
parent 9b8b82b549
commit 61b9b2575c
23 changed files with 431 additions and 432 deletions

View File

@ -65,7 +65,7 @@
common kind of unidirectional association.
</para>
<programlisting><![CDATA[<class name="Person">
<programlisting role="XML"><![CDATA[<class name="Person">
<id name="id" column="personId">
<generator class="native"/>
</id>
@ -94,7 +94,7 @@ create table Address ( addressId bigint not null primary key )
is almost identical. The only difference is the column unique constraint.
</para>
<programlisting><![CDATA[<class name="Person">
<programlisting role="XML"><![CDATA[<class name="Person">
<id name="id" column="personId">
<generator class="native"/>
</id>
@ -120,7 +120,7 @@ create table Address ( addressId bigint not null primary key )
of the association:
</para>
<programlisting><![CDATA[<class name="Person">
<programlisting role="XML"><![CDATA[<class name="Person">
<id name="id" column="personId">
<generator class="native"/>
</id>
@ -149,7 +149,7 @@ create table Address ( personId bigint not null primary key )
is an unusual case, and is not recommended.
</para>
<programlisting><![CDATA[<class name="Person">
<programlisting role="XML"><![CDATA[<class name="Person">
<id name="id" column="personId">
<generator class="native"/>
</id>
@ -190,7 +190,7 @@ create table Address ( addressId bigint not null primary key, personId bigint no
changes the multiplicity from many-to-many to one-to-many.
</para>
<programlisting><![CDATA[<class name="Person">
<programlisting role="XML"><![CDATA[<class name="Person">
<id name="id" column="personId">
<generator class="native"/>
</id>
@ -223,7 +223,7 @@ create table Address ( addressId bigint not null primary key )
is common when the association is optional. For example:
</para>
<programlisting><![CDATA[<class name="Person">
<programlisting role="XML"><![CDATA[<class name="Person">
<id name="id" column="personId">
<generator class="native"/>
</id>
@ -257,7 +257,7 @@ create table Address ( addressId bigint not null primary key )
but extremely unusual.
</para>
<programlisting><![CDATA[<class name="Person">
<programlisting role="XML"><![CDATA[<class name="Person">
<id name="id" column="personId">
<generator class="native"/>
</id>
@ -292,7 +292,7 @@ create table Address ( addressId bigint not null primary key )
Finally, here is an example of a <emphasis>unidirectional many-to-many association</emphasis>.
</para>
<programlisting><![CDATA[<class name="Person">
<programlisting role="XML"><![CDATA[<class name="Person">
<id name="id" column="personId">
<generator class="native"/>
</id>
@ -330,7 +330,7 @@ create table Address ( addressId bigint not null primary key )
relationship.
</para>
<programlisting><![CDATA[<class name="Person">
<programlisting role="XML"><![CDATA[<class name="Person">
<id name="id" column="personId">
<generator class="native"/>
</id>
@ -362,7 +362,7 @@ create table Address ( addressId bigint not null primary key )
<literal>update="false"</literal> and <literal>insert="false"</literal>:
</para>
<programlisting><![CDATA[<class name="Person">
<programlisting role="XML"><![CDATA[<class name="Person">
<id name="id"/>
...
<many-to-one name="address"
@ -402,7 +402,7 @@ create table Address ( addressId bigint not null primary key )
is common:
</para>
<programlisting><![CDATA[<class name="Person">
<programlisting role="XML"><![CDATA[<class name="Person">
<id name="id" column="personId">
<generator class="native"/>
</id>
@ -429,7 +429,7 @@ create table Address ( addressId bigint not null primary key )
uses the special id generator:
</para>
<programlisting><![CDATA[<class name="Person">
<programlisting role="XML"><![CDATA[<class name="Person">
<id name="id" column="personId">
<generator class="native"/>
</id>
@ -466,7 +466,7 @@ create table Address ( personId bigint not null primary key )
association, on the collection, or on the join.
</para>
<programlisting><![CDATA[<class name="Person">
<programlisting role="XML"><![CDATA[<class name="Person">
<id name="id" column="personId">
<generator class="native"/>
</id>
@ -508,7 +508,7 @@ create table Address ( addressId bigint not null primary key )
but extremely unusual.
</para>
<programlisting><![CDATA[<class name="Person">
<programlisting role="XML"><![CDATA[<class name="Person">
<id name="id" column="personId">
<generator class="native"/>
</id>
@ -553,7 +553,7 @@ create table Address ( addressId bigint not null primary key )
Here is an example of a <emphasis>bidirectional many-to-many association</emphasis>.
</para>
<programlisting><![CDATA[<class name="Person">
<programlisting role="XML"><![CDATA[<class name="Person">
<id name="id" column="personId">
<generator class="native"/>
</id>
@ -597,7 +597,7 @@ create table Address ( addressId bigint not null primary key )
and <literal>effectiveStartDate</literal>columns, it would be mapped as follows:
</para>
<programlisting><![CDATA[<properties name="currentAccountKey">
<programlisting role="XML"><![CDATA[<properties name="currentAccountKey">
<property name="accountNumber" type="string" not-null="true"/>
<property name="currentAccount" type="boolean">
<formula>case when effectiveEndDate is null then 1 else 0 end</formula>
@ -611,7 +611,7 @@ create table Address ( addressId bigint not null primary key )
the one with null <literal>effectiveEndDate</literal>, by using:
</para>
<programlisting><![CDATA[<many-to-one name="currentAccountInfo"
<programlisting role="XML"><![CDATA[<many-to-one name="currentAccountInfo"
property-ref="currentAccountKey"
class="AccountInfo">
<column name="accountNumber"/>
@ -626,7 +626,7 @@ create table Address ( addressId bigint not null primary key )
the one with the most recent <literal>startDate</literal>, could be mapped in the following way:
</para>
<programlisting><![CDATA[<join>
<programlisting role="XML"><![CDATA[<join>
<key column="employeeId"/>
<subselect>
select employeeId, orgId
@ -646,6 +646,5 @@ create table Address ( addressId bigint not null primary key )
</sect1>
</chapter>

View File

@ -48,7 +48,7 @@
Here is an example mapping:
</para>
<programlisting id="mapping-declaration-ex1" revision="1"><![CDATA[<?xml version="1.0"?>
<programlisting id="mapping-declaration-ex1" role="XML"><![CDATA[<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
@ -166,7 +166,7 @@
<para>
The following is an example of utilizing user namespacing:
</para>
<programlisting><![CDATA[<?xml version="1.0"?>
<programlisting role="XML"><![CDATA[<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" [
@ -202,7 +202,7 @@
to use unqualified class names in the query language.
</para>
<programlistingco>
<programlistingco role="XML">
<areaspec>
<area id="hm1" coords="2 55"/>
<area id="hm2" coords="3 55"/>
@ -212,7 +212,7 @@
<area id="hm6" coords="7 55"/>
<area id="hm7" coords="8 55"/>
</areaspec>
<programlisting><![CDATA[<hibernate-mapping
<programlisting role="XML"><![CDATA[<hibernate-mapping
schema="schemaName"
catalog="catalogName"
default-cascade="cascade_style"
@ -293,7 +293,7 @@
You can declare a persistent class using the <literal>class</literal> element. For example:
</para>
<programlistingco>
<programlistingco role="XML">
<areaspec>
<area id="class1" coords="2 55"/>
<area id="class2" coords="3 55" />
@ -317,7 +317,7 @@
<area id="class20" coords="21 55"/>
<area id="class21" coords="22 55"/>
</areaspec>
<programlisting><![CDATA[<class
<programlisting role="XML"><![CDATA[<class
name="ClassName"
table="tableName"
discriminator-value="discriminator_value"
@ -581,7 +581,7 @@
immutable and read-only entity to a given SQL subselect expression:
</para>
<programlisting><![CDATA[<class name="Summary">
<programlisting role="XML"><![CDATA[<class name="Summary">
<subselect>
select item.name, max(bid.amount), count(*)
from item
@ -613,7 +613,7 @@
property to the primary key column.
</para>
<programlistingco>
<programlistingco role="XML">
<areaspec>
<area id="id1" coords="2 70"/>
<area id="id2" coords="3 70" />
@ -621,7 +621,7 @@
<area id="id4" coords="5 70" />
<area id="id5" coords="6 70" />
</areaspec>
<programlisting><![CDATA[<id
<programlisting role="XML"><![CDATA[<id
name="propertyName"
type="typename"
column="column_name"
@ -689,7 +689,7 @@
<literal>&lt;param&gt;</literal> element.
</para>
<programlisting><![CDATA[<id name="id" type="long" column="cat_id">
<programlisting role="XML"><![CDATA[<id name="id" type="long" column="cat_id">
<generator class="org.hibernate.id.TableHiLoGenerator">
<param name="table">uid_table</param>
<param name="column">next_hi_value_column</param>
@ -840,7 +840,7 @@
Where supported, the second uses an Oracle-style sequence.
</para>
<programlisting><![CDATA[<id name="id" type="long" column="cat_id">
<programlisting role="XML"><![CDATA[<id name="id" type="long" column="cat_id">
<generator class="hilo">
<param name="table">hi_value</param>
<param name="column">next_value</param>
@ -848,7 +848,7 @@
</generator>
</id>]]></programlisting>
<programlisting><![CDATA[<id name="id" type="long" column="cat_id">
<programlisting role="XML"><![CDATA[<id name="id" type="long" column="cat_id">
<generator class="seqhilo">
<param name="sequence">hi_value</param>
<param name="max_lo">100</param>
@ -883,13 +883,13 @@
two SQL queries to insert a new object. For example:
</para>
<programlisting><![CDATA[<id name="id" type="long" column="person_id">
<programlisting role="XML"><![CDATA[<id name="id" type="long" column="person_id">
<generator class="sequence">
<param name="sequence">person_id_sequence</param>
</generator>
</id>]]></programlisting>
<programlisting><![CDATA[<id name="id" type="long" column="person_id" unsaved-value="0">
<programlisting role="XML"><![CDATA[<id name="id" type="long" column="person_id" unsaved-value="0">
<generator class="identity"/>
</id>]]></programlisting>
@ -926,7 +926,7 @@
Hibernate does not generate DDL with triggers. It is for legacy schemas only.
</para>
<programlisting><![CDATA[<id name="id" type="long" column="person_id">
<programlisting role="XML"><![CDATA[<id name="id" type="long" column="person_id">
<generator class="select">
<param name="key">socialSecurityNumber</param>
</generator>
@ -1112,7 +1112,7 @@
<sect2 id="mapping-declaration-compositeid" revision="3">
<title>composite-id</title>
<programlisting><![CDATA[<composite-id
<programlisting role="XML"><![CDATA[<composite-id
name="propertyName"
class="ClassName"
mapped="true|false"
@ -1131,7 +1131,7 @@
<literal>&lt;key-many-to-one&gt;</literal> mappings as child elements.
</para>
<programlisting><![CDATA[<composite-id>
<programlisting role="XML"><![CDATA[<composite-id>
<key-property name="medicareNumber"/>
<key-property name="dependent"/>
</composite-id>]]></programlisting>
@ -1157,7 +1157,7 @@
element are duplicated on both the persistent class and a separate identifier class.
</para>
<programlisting><![CDATA[<composite-id class="MedicareId" mapped="true">
<programlisting role="XML"><![CDATA[<composite-id class="MedicareId" mapped="true">
<key-property name="medicareNumber"/>
<key-property name="dependent"/>
</composite-id>]]></programlisting>
@ -1239,7 +1239,7 @@
<literal>yes_no</literal>, <literal>true_false</literal>.
</para>
<programlistingco>
<programlistingco role="XML">
<areaspec>
<area id="discriminator1" coords="2 60"/>
<area id="discriminator2" coords="3 60" />
@ -1247,7 +1247,7 @@
<area id="discriminator4" coords="5 60" />
<area id="discriminator5" coords="6 60" />
</areaspec>
<programlisting><![CDATA[<discriminator
<programlisting role="XML"><![CDATA[<discriminator
column="discriminator_column"
type="discriminator_type"
force="true|false"
@ -1308,7 +1308,7 @@
that will be used to evaluate the type of a row. For example:
</para>
<programlisting><![CDATA[<discriminator
<programlisting role="XML"><![CDATA[<discriminator
formula="case when CLASS_TYPE in ('a', 'b', 'c') then 0 else 1 end"
type="integer"/>]]></programlisting>
@ -1323,7 +1323,7 @@
use <emphasis>long transactions</emphasis>. See below for more information:
</para>
<programlistingco>
<programlistingco role="XML">
<areaspec>
<area id="version1" coords="2 70"/>
<area id="version2" coords="3 70"/>
@ -1333,7 +1333,7 @@
<area id="version6" coords="7 70"/>
<area id="version7" coords="8 70"/>
</areaspec>
<programlisting><![CDATA[<version
<programlisting role="XML"><![CDATA[<version
column="version_column"
name="propertyName"
type="typename"
@ -1419,7 +1419,7 @@
use the timestamps in other ways.
</para>
<programlistingco>
<programlistingco role="XML">
<areaspec>
<area id="timestamp1" coords="2 70"/>
<area id="timestamp2" coords="3 70" />
@ -1428,7 +1428,7 @@
<area id="timestamp5" coords="6 70" />
<area id="timestamp6" coords="7 70" />
</areaspec>
<programlisting><![CDATA[<timestamp
<programlisting role="XML"><![CDATA[<timestamp
column="timestamp_column"
name="propertyName"
access="field|property|ClassName"
@ -1510,7 +1510,7 @@
property of the class.
</para>
<programlistingco>
<programlistingco role="XML">
<areaspec>
<area id="property1" coords="2 70"/>
<area id="property2" coords="3 70"/>
@ -1527,7 +1527,7 @@
<area id="property11" coords="12 70"/>
<area id="property12" coords="13 70"/>
</areaspec>
<programlisting><![CDATA[<property
<programlisting role="XML"><![CDATA[<property
name="propertyName"
column="column_name"
type="typename"
@ -1681,7 +1681,7 @@
clause subquery in the SQL query that loads an instance:
</para>
<programlisting><![CDATA[
<programlisting role="XML"><![CDATA[
<property name="totalPrice"
formula="( SELECT SUM (li.quantity*p.price) FROM LineItem li, Product p
WHERE li.productId = p.productId
@ -1707,7 +1707,7 @@
the primary key column(s) of the target table.
</para>
<programlistingco>
<programlistingco role="XML">
<areaspec>
<area id="manytoone1" coords="2 70"/>
<area id="manytoone2" coords="3 70"/>
@ -1728,7 +1728,7 @@
<area id="manytoone15" coords="16 70"/>
<area id="manytoone16" coords="17 70"/>
</areaspec>
<programlisting><![CDATA[<many-to-one
<programlisting role="XML"><![CDATA[<many-to-one
name="propertyName"
column="column_name"
class="ClassName"
@ -1874,7 +1874,7 @@
Here is an example of a typical <literal>many-to-one</literal> declaration:
</para>
<programlisting><![CDATA[<many-to-one name="product" class="Product" column="PRODUCT_ID"/>]]></programlisting>
<programlisting role="XML"><![CDATA[<many-to-one name="product" class="Product" column="PRODUCT_ID"/>]]></programlisting>
<para>
The <literal>property-ref</literal> attribute should only be used for mapping legacy
@ -1885,13 +1885,13 @@
the SchemaExport tool.
</para>
<programlisting><![CDATA[<property name="serialNumber" unique="true" type="string" column="SERIAL_NUMBER"/>]]></programlisting>
<programlisting role="XML"><![CDATA[<property name="serialNumber" unique="true" type="string" column="SERIAL_NUMBER"/>]]></programlisting>
<para>
Then the mapping for <literal>OrderItem</literal> might use:
</para>
<programlisting><![CDATA[<many-to-one name="product" property-ref="serialNumber" column="PRODUCT_SERIAL_NUMBER"/>]]></programlisting>
<programlisting role="XML"><![CDATA[<many-to-one name="product" property-ref="serialNumber" column="PRODUCT_SERIAL_NUMBER"/>]]></programlisting>
<para>
This is not encouraged, however.
@ -1906,7 +1906,7 @@
If the referenced unique key is the property of a component, you can specify a property path:
</para>
<programlisting><![CDATA[<many-to-one name="owner" property-ref="identity.ssn" column="OWNER_SSN"/>]]></programlisting>
<programlisting role="XML"><![CDATA[<many-to-one name="owner" property-ref="identity.ssn" column="OWNER_SSN"/>]]></programlisting>
</sect2>
@ -1918,7 +1918,7 @@
<literal>one-to-one</literal> element.
</para>
<programlistingco>
<programlistingco role="XML">
<areaspec>
<area id="onetoone1" coords="2 70"/>
<area id="onetoone2" coords="3 70"/>
@ -1931,7 +1931,7 @@
<area id="onetoone9" coords="10 70"/>
<area id="onetoone10" coords="11 70"/>
</areaspec>
<programlisting><![CDATA[<one-to-one
<programlisting role="XML"><![CDATA[<one-to-one
name="propertyName"
class="ClassName"
cascade="cascade_style"
@ -2043,8 +2043,8 @@
<literal>Person</literal> respectively:
</para>
<programlisting><![CDATA[<one-to-one name="person" class="Person"/>]]></programlisting>
<programlisting><![CDATA[<one-to-one name="employee" class="Employee" constrained="true"/>]]></programlisting>
<programlisting role="XML"><![CDATA[<one-to-one name="person" class="Person"/>]]></programlisting>
<programlisting role="XML"><![CDATA[<one-to-one name="employee" class="Employee" constrained="true"/>]]></programlisting>
<para>
Ensure that the primary keys of the related rows in the PERSON and
@ -2052,7 +2052,7 @@
called <literal>foreign</literal>:
</para>
<programlisting><![CDATA[<class name="person" table="PERSON">
<programlisting role="XML"><![CDATA[<class name="person" table="PERSON">
<id name="id" column="PERSON_ID">
<generator class="foreign">
<param name="property">employee</param>
@ -2075,21 +2075,21 @@
<literal>Person</literal>, can be expressed as:
</para>
<programlisting><![CDATA[<many-to-one name="person" class="Person" column="PERSON_ID" unique="true"/>]]></programlisting>
<programlisting role="XML"><![CDATA[<many-to-one name="person" class="Person" column="PERSON_ID" unique="true"/>]]></programlisting>
<para>
This association can be made bidirectional by adding the following to the
<literal>Person</literal> mapping:
</para>
<programlisting><![CDATA[<one-to-one name="employee" class="Employee" property-ref="person"/>]]></programlisting>
<programlisting role="XML"><![CDATA[<one-to-one name="employee" class="Employee" property-ref="person"/>]]></programlisting>
</sect2>
<sect2 id="mapping-declaration-naturalid">
<title>Natural-id</title>
<programlisting><![CDATA[<natural-id mutable="true|false"/>
<programlisting role="XML"><![CDATA[<natural-id mutable="true|false"/>
<property ... />
<many-to-one ... />
......
@ -2134,7 +2134,7 @@
the "Component" examples below:
</para>
<programlistingco>
<programlistingco role="XML">
<areaspec>
<area id="component1" coords="2 45"/>
<area id="component2" coords="3 45"/>
@ -2145,7 +2145,7 @@
<area id="component7" coords="8 45"/>
<area id="component8" coords="9 45"/>
</areaspec>
<programlisting><![CDATA[<component
<programlisting role="XML"><![CDATA[<component
name="propertyName"
class="className"
insert="true|false"
@ -2246,7 +2246,7 @@
unique constraint. For example:
</para>
<programlistingco>
<programlistingco role="XML">
<areaspec>
<area id="properties1" coords="2 45"/>
<area id="properties2" coords="3 45"/>
@ -2254,7 +2254,7 @@
<area id="properties4" coords="5 45"/>
<area id="properties5" coords="6 45"/>
</areaspec>
<programlisting><![CDATA[<properties
<programlisting role="XML"><![CDATA[<properties
name="logicalName"
insert="true|false"
update="true|false"
@ -2307,7 +2307,7 @@
For example, if we have the following <literal>&lt;properties&gt;</literal> mapping:
</para>
<programlisting><![CDATA[<class name="Person">
<programlisting role="XML"><![CDATA[<class name="Person">
<id name="personNumber"/>
...
@ -2324,7 +2324,7 @@
the <literal>Person</literal> table, instead of to the primary key:
</para>
<programlisting><![CDATA[<many-to-one name="person"
<programlisting role="XML"><![CDATA[<many-to-one name="person"
class="Person" property-ref="name">
<column name="firstName"/>
<column name="initial"/>
@ -2347,14 +2347,14 @@
mapping strategy, the <literal>&lt;subclass&gt;</literal> declaration is used. For example:
</para>
<programlistingco>
<programlistingco role="XML">
<areaspec>
<area id="subclass1" coords="2 55"/>
<area id="subclass2" coords="3 55"/>
<area id="subclass3" coords="4 55"/>
<area id="subclass4" coords="5 55"/>
</areaspec>
<programlisting><![CDATA[<subclass
<programlisting role="XML"><![CDATA[<subclass
name="ClassName"
discriminator-value="discriminator_value"
proxy="ProxyInterface"
@ -2418,14 +2418,14 @@
superclass. To do this you use the <literal>&lt;joined-subclass&gt;</literal> element. For example:
</para>
<programlistingco>
<programlistingco role="XML">
<areaspec>
<area id="joinedsubclass1" coords="2 45"/>
<area id="joinedsubclass2" coords="3 45"/>
<area id="joinedsubclass3" coords="4 45"/>
<area id="joinedsubclass4" coords="5 45"/>
</areaspec>
<programlisting><![CDATA[<joined-subclass
<programlisting role="XML"><![CDATA[<joined-subclass
name="ClassName"
table="tablename"
proxy="ProxyInterface"
@ -2478,7 +2478,7 @@
would then be re-written as:
</para>
<programlisting><![CDATA[<?xml version="1.0"?>
<programlisting role="XML"><![CDATA[<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
@ -2530,14 +2530,14 @@
use the <literal>&lt;union-subclass&gt;</literal> mapping. For example:
</para>
<programlistingco>
<programlistingco role="XML">
<areaspec>
<area id="unionsubclass1" coords="2 45"/>
<area id="unionsubclass2" coords="3 45"/>
<area id="unionsubclass3" coords="4 45"/>
<area id="unionsubclass4" coords="5 45"/>
</areaspec>
<programlisting><![CDATA[<union-subclass
<programlisting role="XML"><![CDATA[<union-subclass
name="ClassName"
table="tablename"
proxy="ProxyInterface"
@ -2600,7 +2600,7 @@
properties of one class to several tables that have a one-to-one relationship. For example:
</para>
<programlistingco>
<programlistingco role="XML">
<areaspec>
<area id="join1" coords="2 50"/>
<area id="join2" coords="3 50"/>
@ -2609,7 +2609,7 @@
<area id="join5" coords="6 50"/>
<area id="join6" coords="7 50"/>
</areaspec>
<programlisting><![CDATA[<join
<programlisting role="XML"><![CDATA[<join
table="tablename"
schema="owner"
catalog="catalog"
@ -2676,7 +2676,7 @@
table while preserving value type semantics for all properties:
</para>
<programlisting><![CDATA[<class name="Person"
<programlisting role="XML"><![CDATA[<class name="Person"
table="PERSON">
<id name="id" column="PERSON_ID">...</id>
@ -2708,7 +2708,7 @@
the primary key of the original table. It also defines the foreign key in the joined table:
</para>
<programlistingco>
<programlistingco role="XML">
<areaspec>
<area id="key1" coords="2 50"/>
<area id="key2" coords="3 50"/>
@ -2717,7 +2717,7 @@
<area id="key5" coords="6 50"/>
<area id="key6" coords="7 50"/>
</areaspec>
<programlisting><![CDATA[<key
<programlisting role="XML"><![CDATA[<key
column="columnname"
on-delete="noaction|cascade"
property-ref="propertyName"
@ -2796,7 +2796,7 @@
is an alternative to the <literal>formula</literal> attribute. For example:
</para>
<programlisting><![CDATA[<column
<programlisting role="XML"><![CDATA[<column
name="column_name"
length="N"
precision="N"
@ -2811,7 +2811,7 @@
read="SQL expression"
write="SQL expression"/>]]></programlisting>
<programlisting><![CDATA[<formula>SQL expression</formula>]]></programlisting>
<programlisting role="XML"><![CDATA[<formula>SQL expression</formula>]]></programlisting>
<para>
Most of the attributes on <literal>column</literal> provide a means of tailoring the
@ -2827,7 +2827,7 @@
conditions.
</para>
<programlisting><![CDATA[<many-to-one name="homeAddress" class="Address"
<programlisting role="XML"><![CDATA[<many-to-one name="homeAddress" class="Address"
insert="false" update="false">
<column name="person_id" not-null="true" length="10"/>
<formula>'MAILING'</formula>
@ -2845,14 +2845,14 @@
classes and interfaces that are not explicitly mapped:
</para>
<programlisting><![CDATA[<import class="java.lang.Object" rename="Universe"/>]]></programlisting>
<programlisting role="XML"><![CDATA[<import class="java.lang.Object" rename="Universe"/>]]></programlisting>
<programlistingco>
<programlistingco role="XML">
<areaspec>
<area id="import1" coords="2 40"/>
<area id="import2" coords="3 40"/>
</areaspec>
<programlisting><![CDATA[<import
<programlisting role="XML"><![CDATA[<import
class="ClassName"
rename="ShortName"
/>]]></programlisting>
@ -2893,7 +2893,7 @@
the meta-type to class names.
</para>
<programlisting><![CDATA[<any name="being" id-type="long" meta-type="string">
<programlisting role="XML"><![CDATA[<any name="being" id-type="long" meta-type="string">
<meta-value value="TBL_ANIMAL" class="Animal"/>
<meta-value value="TBL_HUMAN" class="Human"/>
<meta-value value="TBL_ALIEN" class="Alien"/>
@ -2901,7 +2901,7 @@
<column name="id"/>
</any>]]></programlisting>
<programlistingco>
<programlistingco role="XML">
<areaspec>
<area id="any1" coords="2 50"/>
<area id="any2" coords="3 50"/>
@ -2910,7 +2910,7 @@
<area id="any5" coords="6 50"/>
<area id="any6" coords="7 50"/>
</areaspec>
<programlisting><![CDATA[<any
<programlisting role="XML"><![CDATA[<any
name="propertyName"
id-type="idtypename"
meta-type="metatypename"
@ -3217,7 +3217,7 @@
are possible.
</para>
<programlisting><![CDATA[<property name="twoStrings" type="org.hibernate.test.DoubleStringType">
<programlisting role="XML"><![CDATA[<property name="twoStrings" type="org.hibernate.test.DoubleStringType">
<column name="first_string"/>
<column name="second_string"/>
</property>]]></programlisting>
@ -3241,7 +3241,7 @@
files.
</para>
<programlisting><![CDATA[<property name="priority">
<programlisting role="XML"><![CDATA[<property name="priority">
<type name="com.mycompany.usertypes.DefaultValueIntegerType">
<param name="default">0</param>
</type>
@ -3259,11 +3259,11 @@
parameter values if the type is parameterized.
</para>
<programlisting><![CDATA[<typedef class="com.mycompany.usertypes.DefaultValueIntegerType" name="default_zero">
<programlisting role="XML"><![CDATA[<typedef class="com.mycompany.usertypes.DefaultValueIntegerType" name="default_zero">
<param name="default">0</param>
</typedef>]]></programlisting>
<programlisting><![CDATA[<property name="priority" type="default_zero"/>]]></programlisting>
<programlisting role="XML"><![CDATA[<property name="priority" type="default_zero"/>]]></programlisting>
<para>
It is also possible to override the parameters supplied in a typedef on a case-by-case basis
@ -3329,7 +3329,7 @@
Server uses brackets and MySQL uses backticks.
</para>
<programlisting><![CDATA[<class name="LineItem" table="`Line Item`">
<programlisting role="XML"><![CDATA[<class name="LineItem" table="`Line Item`">
<id name="id" column="`Item Id`"/><generator class="assigned"/></id>
<property name="itemNumber" column="`Item #`"/>
...
@ -3355,7 +3355,7 @@
following example of the <literal>Cat</literal> class with XDoclet mappings:
</para>
<programlisting><![CDATA[package eg;
<programlisting role="JAVA"><![CDATA[package eg;
import java.util.Set;
import java.util.Date;
@ -3484,7 +3484,7 @@ public class Cat {
This is an example of a POJO class annotated as an EJB entity bean:
</para>
<programlisting><![CDATA[@Entity(access = AccessType.FIELD)
<programlisting role="JAVA"><![CDATA[@Entity(access = AccessType.FIELD)
public class Customer implements Serializable {
@Id;
@ -3561,7 +3561,7 @@ public class Customer implements Serializable {
of columns mapped to <link linkend="mapping-declaration-property">simple properties</link>.
For example, if your database provides a set of data encryption functions, you can
invoke them for individual columns like this:
<programlisting><![CDATA[<property name="creditCardNumber">
<programlisting role="XML"><![CDATA[<property name="creditCardNumber">
<column
name="credit_card_num"
read="decrypt(credit_card_num)"
@ -3607,7 +3607,7 @@ public class Customer implements Serializable {
The first mode is to explicitly list the CREATE and DROP commands in the mapping
file:
</para>
<programlisting><![CDATA[<hibernate-mapping>
<programlisting role="XML"><![CDATA[<hibernate-mapping>
...
<database-object>
<create>CREATE TRIGGER my_trigger ...</create>
@ -3619,7 +3619,7 @@ public class Customer implements Serializable {
CREATE and DROP commands. This custom class must implement the
<literal>org.hibernate.mapping.AuxiliaryDatabaseObject</literal> interface.
</para>
<programlisting><![CDATA[<hibernate-mapping>
<programlisting role="XML"><![CDATA[<hibernate-mapping>
...
<database-object>
<definition class="MyTriggerDefinition"/>
@ -3629,7 +3629,7 @@ public class Customer implements Serializable {
Additionally, these database objects can be optionally scoped so that they only
apply when certain dialects are used.
</para>
<programlisting><![CDATA[<hibernate-mapping>
<programlisting role="XML"><![CDATA[<hibernate-mapping>
...
<database-object>
<definition class="MyTriggerDefinition"/>

View File

@ -33,7 +33,7 @@
look like this:
</para>
<programlisting><![CDATA[Session session = sessionFactory.openSession();
<programlisting role="JAVA"><![CDATA[Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
for ( int i=0; i<100000; i++ ) {
Customer customer = new Customer(.....);
@ -84,7 +84,7 @@ session.close();]]></programlisting>
the first-level cache.
</para>
<programlisting><![CDATA[Session session = sessionFactory.openSession();
<programlisting role="JAVA"><![CDATA[Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
for ( int i=0; i<100000; i++ ) {
@ -111,7 +111,7 @@ session.close();]]></programlisting>
queries that return many rows of data.
</para>
<programlisting><![CDATA[Session session = sessionFactory.openSession();
<programlisting role="JAVA"><![CDATA[Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
ScrollableResults customers = session.getNamedQuery("GetCustomers")
@ -150,7 +150,7 @@ session.close();]]></programlisting>
session is a lower-level abstraction that is much closer to the underlying JDBC.
</para>
<programlisting><![CDATA[StatelessSession session = sessionFactory.openStatelessSession();
<programlisting role="JAVA"><![CDATA[StatelessSession session = sessionFactory.openStatelessSession();
Transaction tx = session.beginTransaction();
ScrollableResults customers = session.getNamedQuery("GetCustomers")
@ -237,7 +237,7 @@ session.close();]]></programlisting>
those familiar with JDBC's <literal>PreparedStatement.executeUpdate()</literal>:
</para>
<programlisting><![CDATA[Session session = sessionFactory.openSession();
<programlisting role="JAVA"><![CDATA[Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
String hqlUpdate = "update Customer c set c.name = :newName where c.name = :oldName";
@ -259,7 +259,7 @@ session.close();]]></programlisting>
This is achieved by adding the <literal>VERSIONED</literal> keyword after the <literal>UPDATE</literal>
keyword.
</para>
<programlisting><![CDATA[Session session = sessionFactory.openSession();
<programlisting role="JAVA"><![CDATA[Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
String hqlVersionedUpdate = "update versioned Customer set name = :newName where name = :oldName";
int updatedEntities = s.createQuery( hqlUpdate )
@ -279,7 +279,7 @@ session.close();]]></programlisting>
method:
</para>
<programlisting><![CDATA[Session session = sessionFactory.openSession();
<programlisting role="JAVA"><![CDATA[Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
String hqlDelete = "delete Customer c where c.name = :oldName";
@ -363,7 +363,7 @@ session.close();]]></programlisting>
The following is an example of an HQL <literal>INSERT</literal> statement execution:
</para>
<programlisting><![CDATA[Session session = sessionFactory.openSession();
<programlisting role="JAVA"><![CDATA[Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
String hqlInsert = "insert into DelinquentAccount (id, name) select c.id, c.name from Customer c where ...";

View File

@ -36,7 +36,7 @@
as an interface type. For example:
</para>
<programlisting><![CDATA[public class Product {
<programlisting role="JAVA"><![CDATA[public class Product {
private String serialNumber;
private Set parts = new HashSet();
@ -65,7 +65,7 @@
Be aware of the following errors:
</para>
<programlisting><![CDATA[Cat cat = new DomesticCat();
<programlisting role="JAVA"><![CDATA[Cat cat = new DomesticCat();
Cat kitten = new DomesticCat();
....
Set kittens = new HashSet();
@ -118,7 +118,7 @@ kittens = cat.getKittens(); // Okay, kittens collection is a Set
element is used for mapping properties of type <literal>Set</literal>.
</para>
<programlisting><![CDATA[<class name="Product">
<programlisting role="JAVA"><![CDATA[<class name="Product">
<id name="serialNumber" column="productSerialNumber"/>
<set name="parts">
<key column="productSerialNumber" not-null="true"/>
@ -134,7 +134,7 @@ kittens = cat.getKittens(); // Okay, kittens collection is a Set
<literal>&lt;map&gt;</literal> element is representative:
</para>
<programlistingco>
<programlistingco role="XML">
<areaspec>
<area id="mappingcollection1" coords="2 65"/>
<area id="mappingcollection2" coords="3 65"/>
@ -151,7 +151,7 @@ kittens = cat.getKittens(); // Okay, kittens collection is a Set
<area id="mappingcollection13" coords="14 65"/>
<area id="mappingcollection14" coords="15 65"/>
</areaspec>
<programlisting><![CDATA[<map
<programlisting role="XML"><![CDATA[<map
name="propertyName"
table="table_name"
schema="schema_name"
@ -288,13 +288,13 @@ kittens = cat.getKittens(); // Okay, kittens collection is a Set
<literal>not-null="true"</literal>.
</para>
<programlisting><![CDATA[<key column="productSerialNumber" not-null="true"/>]]></programlisting>
<programlisting role="XML"><![CDATA[<key column="productSerialNumber" not-null="true"/>]]></programlisting>
<para>
The foreign key constraint can use <literal>ON DELETE CASCADE</literal>.
</para>
<programlisting><![CDATA[<key column="productSerialNumber" on-delete="cascade"/>]]></programlisting>
<programlisting role="XML"><![CDATA[<key column="productSerialNumber" on-delete="cascade"/>]]></programlisting>
<para>
See the previous chapter for a full definition of the <literal>&lt;key&gt;</literal>
@ -342,12 +342,12 @@ kittens = cat.getKittens(); // Okay, kittens collection is a Set
sequential integers that are numbered from zero by default.
</para>
<programlistingco>
<programlistingco role="XML">
<areaspec>
<area id="index1" coords="2 45"/>
<area id="index2" coords="3 45"/>
</areaspec>
<programlisting><![CDATA[<list-index
<programlisting role="XML"><![CDATA[<list-index
column="column_name"
base="0|1|..."/>]]></programlisting>
<calloutlist>
@ -366,13 +366,13 @@ kittens = cat.getKittens(); // Okay, kittens collection is a Set
</calloutlist>
</programlistingco>
<programlistingco>
<programlistingco role="XML">
<areaspec>
<area id="mapkey1" coords="2 45"/>
<area id="mapkey2" coords="3 45"/>
<area id="mapkey3" coords="4 45"/>
</areaspec>
<programlisting><![CDATA[<map-key
<programlisting role="XML"><![CDATA[<map-key
column="column_name"
formula="any SQL expression"
type="type_name"
@ -399,13 +399,13 @@ kittens = cat.getKittens(); // Okay, kittens collection is a Set
</calloutlist>
</programlistingco>
<programlistingco>
<programlistingco role="XML">
<areaspec>
<area id="indexmanytomany1" coords="2 45"/>
<area id="indexmanytomany2" coords="3 45"/>
<area id="indexmanytomany3" coords="3 45"/>
</areaspec>
<programlisting><![CDATA[<map-key-many-to-many
<programlisting role="XML"><![CDATA[<map-key-many-to-many
column="column_name"
formula="any SQL expression"
class="ClassName"
@ -455,13 +455,13 @@ kittens = cat.getKittens(); // Okay, kittens collection is a Set
For a collection of values use the <literal>&lt;element&gt;</literal> tag. For example:
</para>
<programlistingco>
<programlistingco role="XML">
<areaspec>
<area id="element1b" coords="2 50"/>
<area id="element2b" coords="3 50"/>
<area id="element3b" coords="4 50"/>
</areaspec>
<programlisting><![CDATA[<element
<programlisting role="XML"><![CDATA[<element
column="column_name"
formula="any SQL expression"
type="typename"
@ -498,7 +498,7 @@ kittens = cat.getKittens(); // Okay, kittens collection is a Set
<literal>&lt;many-to-many&gt;</literal> element.
</para>
<programlistingco>
<programlistingco role="XML">
<areaspec>
<area id="manytomany1" coords="2 60"/>
<area id="manytomany2" coords="3 60"/>
@ -509,7 +509,7 @@ kittens = cat.getKittens(); // Okay, kittens collection is a Set
<area id="manytomany7" coords="8 60"/>
<area id="manytomany8" coords="9 60"/>
</areaspec>
<programlisting><![CDATA[<many-to-many
<programlisting role="XML"><![CDATA[<many-to-many
column="column_name"
formula="any SQL expression"
class="ClassName"
@ -586,7 +586,7 @@ kittens = cat.getKittens(); // Okay, kittens collection is a Set
A set of strings:
</para>
<programlisting><![CDATA[<set name="names" table="person_names">
<programlisting role="XML"><![CDATA[<set name="names" table="person_names">
<key column="person_id"/>
<element column="person_name" type="string"/>
</set>]]></programlisting>
@ -596,7 +596,7 @@ kittens = cat.getKittens(); // Okay, kittens collection is a Set
<literal>order-by</literal> attribute:
</para>
<programlisting><![CDATA[<bag name="sizes"
<programlisting role="XML"><![CDATA[<bag name="sizes"
table="item_sizes"
order-by="size asc">
<key column="item_id"/>
@ -607,7 +607,7 @@ kittens = cat.getKittens(); // Okay, kittens collection is a Set
An array of entities, in this case, a many-to-many association:
</para>
<programlisting><![CDATA[<array name="addresses"
<programlisting role="XML"><![CDATA[<array name="addresses"
table="PersonAddress"
cascade="persist">
<key column="personId"/>
@ -619,7 +619,7 @@ kittens = cat.getKittens(); // Okay, kittens collection is a Set
A map from string indices to dates:
</para>
<programlisting><![CDATA[<map name="holidays"
<programlisting role="XML"><![CDATA[<map name="holidays"
table="holidays"
schema="dbo"
order-by="hol_name asc">
@ -632,7 +632,7 @@ kittens = cat.getKittens(); // Okay, kittens collection is a Set
A list of components (this is discussed in the next chapter):
</para>
<programlisting><![CDATA[<list name="carComponents"
<programlisting role="XML"><![CDATA[<list name="carComponents"
table="CarComponents">
<key column="carId"/>
<list-index column="sortOrder"/>
@ -676,13 +676,13 @@ kittens = cat.getKittens(); // Okay, kittens collection is a Set
association.
</para>
<programlistingco>
<programlistingco role="XML">
<areaspec>
<area id="onetomany1" coords="2 60"/>
<area id="onetomany2" coords="3 60"/>
<area id="onetomany3" coords="4 60"/>
</areaspec>
<programlisting><![CDATA[<one-to-many
<programlisting role="XML"><![CDATA[<one-to-many
class="ClassName"
not-found="ignore|exception"
entity-name="EntityName"
@ -734,7 +734,7 @@ kittens = cat.getKittens(); // Okay, kittens collection is a Set
Notice the use of a formula-based index:
</para>
<programlisting><![CDATA[<map name="parts"
<programlisting role="XML"><![CDATA[<map name="parts"
cascade="all">
<key column="productId" not-null="true"/>
<map-key formula="partName"/>
@ -755,7 +755,7 @@ kittens = cat.getKittens(); // Okay, kittens collection is a Set
<literal>java.util.SortedSet</literal>. You must specify a comparator in the mapping file:
</para>
<programlisting><![CDATA[<set name="aliases"
<programlisting role="XML"><![CDATA[<set name="aliases"
table="person_aliases"
sort="natural">
<key column="person"/>
@ -788,7 +788,7 @@ kittens = cat.getKittens(); // Okay, kittens collection is a Set
not in the memory.
</para>
<programlisting><![CDATA[<set name="aliases" table="person_aliases" order-by="lower(name) asc">
<programlisting role="XML"><![CDATA[<set name="aliases" table="person_aliases" order-by="lower(name) asc">
<key column="person"/>
<element column="name" type="string"/>
</set>
@ -812,7 +812,7 @@ kittens = cat.getKittens(); // Okay, kittens collection is a Set
<literal>filter()</literal>:
</para>
<programlisting><![CDATA[sortedUsers = s.createFilter( group.getUsers(), "order by this.name" ).list();]]></programlisting>
<programlisting role="JAVA"><![CDATA[sortedUsers = s.createFilter( group.getUsers(), "order by this.name" ).list();]]></programlisting>
</sect2>
@ -857,7 +857,7 @@ kittens = cat.getKittens(); // Okay, kittens collection is a Set
have many items and each item can be in many categories:
</para>
<programlisting><![CDATA[<class name="Category">
<programlisting role="XML"><![CDATA[<class name="Category">
<id name="id" column="CATEGORY_ID"/>
...
<bag name="items" table="CATEGORY_ITEM">
@ -885,7 +885,7 @@ kittens = cat.getKittens(); // Okay, kittens collection is a Set
a many-to-many relationship in Javais created:
</para>
<programlisting><![CDATA[
<programlisting role="JAVA"><![CDATA[
category.getItems().add(item); // The category now "knows" about the relationship
item.getCategories().add(category); // The item now "knows" about the relationship
@ -902,7 +902,7 @@ session.persist(category); // The relationship will be saved]]></p
end <literal>inverse="true"</literal>.
</para>
<programlisting><![CDATA[<class name="Parent">
<programlisting role="XML"><![CDATA[<class name="Parent">
<id name="id" column="parent_id"/>
....
<set name="children" inverse="true">
@ -936,7 +936,7 @@ session.persist(category); // The relationship will be saved]]></p
<literal>inverse="true"</literal> on the collection mapping:
</para>
<programlisting><![CDATA[<class name="Parent">
<programlisting role="XML"><![CDATA[<class name="Parent">
<id name="id" column="parent_id"/>
....
<map name="children" inverse="true">
@ -965,7 +965,7 @@ session.persist(category); // The relationship will be saved]]></p
<literal>inverse="true"</literal>. Instead, you could use the following mapping:
</para>
<programlisting><![CDATA[<class name="Parent">
<programlisting role="XML"><![CDATA[<class name="Parent">
<id name="id" column="parent_id"/>
....
<map name="children">
@ -1003,13 +1003,13 @@ session.persist(category); // The relationship will be saved]]></p
<literal>Map</literal> with an association as its index:
</para>
<programlisting><![CDATA[<map name="contracts">
<programlisting role="XML"><![CDATA[<map name="contracts">
<key column="employer_id" not-null="true"/>
<map-key-many-to-many column="employee_id" class="Employee"/>
<one-to-many class="Contract"/>
</map>]]></programlisting>
<programlisting><![CDATA[<map name="connections">
<programlisting role="XML"><![CDATA[<map name="connections">
<key column="incoming_node_id"/>
<map-key-many-to-many column="outgoing_node_id" class="Node"/>
<many-to-many column="connection_id" class="Connection"/>
@ -1044,7 +1044,7 @@ session.persist(category); // The relationship will be saved]]></p
(or <literal>Collection</literal>) with bag semantics. For example:
</para>
<programlisting><![CDATA[<idbag name="lovers" table="LOVERS">
<programlisting role="XML"><![CDATA[<idbag name="lovers" table="LOVERS">
<collection-id column="ID" type="long">
<generator class="sequence"/>
</collection-id>
@ -1099,7 +1099,7 @@ session.persist(category); // The relationship will be saved]]></p
The following class has a collection of <literal>Child</literal> instances:
</para>
<programlisting><![CDATA[package eg;
<programlisting role="JAVA"><![CDATA[package eg;
import java.util.Set;
public class Parent {
@ -1122,7 +1122,7 @@ public class Parent {
</para>
<programlisting><![CDATA[<hibernate-mapping>
<programlisting role="XML"><![CDATA[<hibernate-mapping>
<class name="Parent">
<id name="id">
@ -1147,7 +1147,7 @@ public class Parent {
This maps to the following table definitions:
</para>
<programlisting><![CDATA[create table parent ( id bigint not null primary key )
<programlisting role="XML"><![CDATA[create table parent ( id bigint not null primary key )
create table child ( id bigint not null primary key, name varchar(255), parent_id bigint )
alter table child add constraint childfk0 (parent_id) references parent]]></programlisting>
@ -1156,7 +1156,7 @@ alter table child add constraint childfk0 (parent_id) references parent]]></prog
association:
</para>
<programlisting><![CDATA[<hibernate-mapping>
<programlisting role="XML"><![CDATA[<hibernate-mapping>
<class name="Parent">
<id name="id">
@ -1182,7 +1182,7 @@ alter table child add constraint childfk0 (parent_id) references parent]]></prog
Notice the <literal>NOT NULL</literal> constraint:
</para>
<programlisting><![CDATA[create table parent ( id bigint not null primary key )
<programlisting role="XML"><![CDATA[create table parent ( id bigint not null primary key )
create table child ( id bigint not null
primary key,
name varchar(255),
@ -1195,7 +1195,7 @@ alter table child add constraint childfk0 (parent_id) references parent]]></prog
mapping:
</para>
<programlisting><![CDATA[<hibernate-mapping>
<programlisting role="XML"><![CDATA[<hibernate-mapping>
<class name="Parent">
<id name="id">
@ -1221,7 +1221,7 @@ alter table child add constraint childfk0 (parent_id) references parent]]></prog
association is appropriate:
</para>
<programlisting><![CDATA[<hibernate-mapping>
<programlisting role="XML"><![CDATA[<hibernate-mapping>
<class name="Parent">
<id name="id">

View File

@ -42,7 +42,7 @@
and not to architecture-level components. For example, you can model a person like this:
</para>
<programlisting><![CDATA[public class Person {
<programlisting role="JAVA"><![CDATA[public class Person {
private java.util.Date birthday;
private Name name;
private String key;
@ -68,7 +68,7 @@
......
}]]></programlisting>
<programlisting><![CDATA[public class Name {
<programlisting role="JAVA"><![CDATA[public class Name {
char initial;
String first;
String last;
@ -103,7 +103,7 @@
Our Hibernate mapping would look like this:
</para>
<programlisting><![CDATA[<class name="eg.Person" table="person">
<programlisting role="XML"><![CDATA[<class name="eg.Person" table="person">
<id name="Key" column="pid" type="string">
<generator class="uuid"/>
</id>
@ -144,7 +144,7 @@
containing entity.
</para>
<programlisting><![CDATA[<class name="eg.Person" table="person">
<programlisting role="XML"><![CDATA[<class name="eg.Person" table="person">
<id name="Key" column="pid" type="string">
<generator class="uuid"/>
</id>
@ -169,7 +169,7 @@
<literal>&lt;composite-element&gt;</literal> tag:
</para>
<programlisting><![CDATA[<set name="someNames" table="some_names" lazy="true">
<programlisting role="XML"><![CDATA[<set name="someNames" table="some_names" lazy="true">
<key column="id"/>
<composite-element class="eg.Name"> <!-- class attribute required -->
<property name="initial"/>
@ -219,7 +219,7 @@
<literal>quantity</literal> are properties of the association:
</para>
<programlisting><![CDATA[<class name="eg.Order" .... >
<programlisting role="XML"><![CDATA[<class name="eg.Order" .... >
....
<set name="purchasedItems" table="purchase_items" lazy="true">
<key column="order_id">
@ -242,7 +242,7 @@
<para>Even ternary (or quaternary, etc) associations are possible:</para>
<programlisting><![CDATA[<class name="eg.Order" .... >
<programlisting role="XML"><![CDATA[<class name="eg.Order" .... >
....
<set name="purchasedItems" table="purchase_items" lazy="true">
<key column="order_id">
@ -315,7 +315,7 @@
the (composite) primary key of <literal>Order</literal>.
</para>
<programlisting><![CDATA[<class name="OrderLine">
<programlisting role="XML"><![CDATA[<class name="OrderLine">
<composite-id name="id" class="OrderLineId">
<key-property name="lineId"/>
@ -340,7 +340,7 @@
to <literal>OrderLine</literal> is mapped like this:
</para>
<programlisting><![CDATA[<many-to-one name="orderLine" class="OrderLine">
<programlisting role="XML"><![CDATA[<many-to-one name="orderLine" class="OrderLine">
<!-- the "class" attribute is optional, as usual -->
<column name="lineId"/>
<column name="orderId"/>
@ -362,7 +362,7 @@
uses the composite foreign key:
</para>
<programlisting><![CDATA[<set name="undeliveredOrderLines">
<programlisting role="XML"><![CDATA[<set name="undeliveredOrderLines">
<key column name="warehouseId"/>
<many-to-many class="OrderLine">
<column name="lineId"/>
@ -376,7 +376,7 @@
use:
</para>
<programlisting><![CDATA[<set name="orderLines" inverse="true">
<programlisting role="XML"><![CDATA[<set name="orderLines" inverse="true">
<key>
<column name="orderId"/>
<column name="customerId"/>
@ -393,7 +393,7 @@
foreign key.
</para>
<programlisting><![CDATA[<class name="OrderLine">
<programlisting role="XML"><![CDATA[<class name="OrderLine">
....
....
<list name="deliveryAttempts">
@ -418,7 +418,7 @@
You can also map a property of type <literal>Map</literal>:
</para>
<programlisting><![CDATA[<dynamic-component name="userAttributes">
<programlisting role="XML"><![CDATA[<dynamic-component name="userAttributes">
<property name="foo" column="FOO" type="string"/>
<property name="bar" column="BAR" type="integer"/>
<many-to-one name="baz" class="Baz" column="BAZ_ID"/>

View File

@ -52,7 +52,7 @@
use <literal>addResource()</literal>. For example:
</para>
<programlisting><![CDATA[Configuration cfg = new Configuration()
<programlisting role="JAVA"><![CDATA[Configuration cfg = new Configuration()
.addResource("Item.hbm.xml")
.addResource("Bid.hbm.xml");]]></programlisting>
@ -61,7 +61,7 @@
allow Hibernate to find the mapping document for you:
</para>
<programlisting><![CDATA[Configuration cfg = new Configuration()
<programlisting role="JAVA"><![CDATA[Configuration cfg = new Configuration()
.addClass(org.hibernate.auction.Item.class)
.addClass(org.hibernate.auction.Bid.class);]]></programlisting>
@ -76,7 +76,7 @@
properties. For example:
</para>
<programlisting><![CDATA[Configuration cfg = new Configuration()
<programlisting role="JAVA"><![CDATA[Configuration cfg = new Configuration()
.addClass(org.hibernate.auction.Item.class)
.addClass(org.hibernate.auction.Bid.class)
.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect")
@ -133,7 +133,7 @@
This factory is intended to be shared by all application threads:
</para>
<programlisting><![CDATA[SessionFactory sessions = cfg.buildSessionFactory();]]></programlisting>
<programlisting role="JAVA"><![CDATA[SessionFactory sessions = cfg.buildSessionFactory();]]></programlisting>
<para>
Hibernate does allow your application to instantiate more than one
@ -152,7 +152,7 @@
is as simple as:
</para>
<programlisting><![CDATA[Session session = sessions.openSession(); // open a new Session]]></programlisting>
<programlisting role="JAVA"><![CDATA[Session session = sessions.openSession(); // open a new Session]]></programlisting>
<para>
Once you start a task that requires access to the database, a JDBC connection will be obtained from
@ -1344,7 +1344,7 @@ hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect]]></programlisting>
<literal>Configuration.setNamingStrategy()</literal> before adding mappings:
</para>
<programlisting><![CDATA[SessionFactory sf = new Configuration()
<programlisting role="JAVA"><![CDATA[SessionFactory sf = new Configuration()
.setNamingStrategy(ImprovedNamingStrategy.INSTANCE)
.addFile("Item.hbm.xml")
.addFile("Bid.hbm.xml")
@ -1372,7 +1372,7 @@ hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect]]></programlisting>
your <literal>CLASSPATH</literal>. Here is an example:
</para>
<programlisting><![CDATA[<?xml version='1.0' encoding='utf-8'?>
<programlisting role="XML"><![CDATA[<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
@ -1418,13 +1418,13 @@ hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect]]></programlisting>
With the XML configuration, starting Hibernate is then as simple as:
</para>
<programlisting><![CDATA[SessionFactory sf = new Configuration().configure().buildSessionFactory();]]></programlisting>
<programlisting role="JAVA"><![CDATA[SessionFactory sf = new Configuration().configure().buildSessionFactory();]]></programlisting>
<para>
You can select a different XML configuration file using:
</para>
<programlisting><![CDATA[SessionFactory sf = new Configuration()
<programlisting role="JAVA"><![CDATA[SessionFactory sf = new Configuration()
.configure("catdb.cfg.xml")
.buildSessionFactory();]]></programlisting>
@ -1701,7 +1701,7 @@ hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect]]></programlisting>
<literal>jboss-service.xml</literal> for JBoss 4.0.x:
</para>
<programlisting><![CDATA[<?xml version="1.0"?>
<programlisting role="XML"><![CDATA[<?xml version="1.0"?>
<server>
<mbean code="org.hibernate.jmx.HibernateService"

View File

@ -53,7 +53,7 @@
<literal>EmptyInterceptor</literal>.
</para>
<programlisting><![CDATA[package org.hibernate.test;
<programlisting role="JAVA"><![CDATA[package org.hibernate.test;
import java.io.Serializable;
import java.util.Date;
@ -147,7 +147,7 @@ public class AuditInterceptor extends EmptyInterceptor {
methods accepting an <literal>Interceptor</literal>.
</para>
<programlisting><![CDATA[Session session = sf.openSession( new AuditInterceptor() );]]></programlisting>
<programlisting role="JAVA"><![CDATA[Session session = sf.openSession( new AuditInterceptor() );]]></programlisting>
<para>
A <literal>SessionFactory</literal>-scoped interceptor is registered with the <literal>Configuration</literal>
@ -158,7 +158,7 @@ public class AuditInterceptor extends EmptyInterceptor {
sessions will use this interceptor potentially concurrently.
</para>
<programlisting><![CDATA[new Configuration().setInterceptor( new AuditInterceptor() );]]></programlisting>
<programlisting role="JAVA"><![CDATA[new Configuration().setInterceptor( new AuditInterceptor() );]]></programlisting>
</sect1>
@ -201,7 +201,7 @@ public class AuditInterceptor extends EmptyInterceptor {
example of a custom load event listener:
</para>
<programlisting><![CDATA[public class MyLoadListener implements LoadEventListener {
<programlisting role="JAVA"><![CDATA[public class MyLoadListener implements LoadEventListener {
// this is the single method defined by the LoadEventListener interface
public void onLoad(LoadEvent event, LoadEventListener.LoadType loadType)
throws HibernateException {
@ -216,7 +216,7 @@ public class AuditInterceptor extends EmptyInterceptor {
to the default listener:
</para>
<programlisting><![CDATA[<hibernate-configuration>
<programlisting role="XML"><![CDATA[<hibernate-configuration>
<session-factory>
...
<event type="load">
@ -230,7 +230,7 @@ public class AuditInterceptor extends EmptyInterceptor {
Instead, you can register it programmatically:
</para>
<programlisting><![CDATA[Configuration cfg = new Configuration();
<programlisting role="JAVA"><![CDATA[Configuration cfg = new Configuration();
LoadEventListener[] stack = { new MyLoadListener(), new DefaultLoadEventListener() };
cfg.EventListeners().setLoadEventListeners(stack);]]></programlisting>
@ -264,7 +264,7 @@ cfg.EventListeners().setLoadEventListeners(stack);]]></programlisting>
authorization.
</para>
<programlisting><![CDATA[<listener type="pre-delete" class="org.hibernate.secure.JACCPreDeleteEventListener"/>
<programlisting role="XML"><![CDATA[<listener type="pre-delete" class="org.hibernate.secure.JACCPreDeleteEventListener"/>
<listener type="pre-update" class="org.hibernate.secure.JACCPreUpdateEventListener"/>
<listener type="pre-insert" class="org.hibernate.secure.JACCPreInsertEventListener"/>
<listener type="pre-load" class="org.hibernate.secure.JACCPreLoadEventListener"/>]]></programlisting>
@ -279,7 +279,7 @@ cfg.EventListeners().setLoadEventListeners(stack);]]></programlisting>
Next, while still in <literal>hibernate.cfg.xml</literal>, bind the permissions to roles:
</para>
<programlisting><![CDATA[<grant role="admin" entity-name="User" actions="insert,update,read"/>
<programlisting role="XML"><![CDATA[<grant role="admin" entity-name="User" actions="insert,update,read"/>
<grant role="su" entity-name="User" actions="*"/>]]></programlisting>
<para>

View File

@ -57,7 +57,7 @@
Here is a possible mapping document:
</para>
<programlisting><![CDATA[<hibernate-mapping>
<programlisting role="XML"><![CDATA[<hibernate-mapping>
<class name="Employer" table="employers">
<id name="id">
@ -171,7 +171,7 @@ create sequence employer_id_seq]]></programlisting>
The following mapping document correctly represents these relationships:
</para>
<programlisting><![CDATA[<hibernate-mapping>
<programlisting role="XML"><![CDATA[<hibernate-mapping>
<class name="Work" table="works" discriminator-value="W">
@ -295,7 +295,7 @@ alter table author_work
The mapping document will look like this:
</para>
<programlisting><![CDATA[<hibernate-mapping>
<programlisting role="XML"><![CDATA[<hibernate-mapping>
<class name="Customer" table="customers">
<id name="id">
@ -389,7 +389,7 @@ alter table line_items
<sect2 id="example-mappings-typed-onetone">
<title>"Typed" one-to-one association</title>
<programlisting><![CDATA[<class name="Person">
<programlisting role="XML"><![CDATA[<class name="Person">
<id name="name"/>
<one-to-one name="address"
cascade="all">
@ -419,7 +419,7 @@ alter table line_items
<sect2 id="example-mappings-composite-key">
<title>Composite key example</title>
<programlisting><![CDATA[<class name="Customer">
<programlisting role="XML"><![CDATA[<class name="Customer">
<id name="customerId"
length="10">
@ -536,7 +536,7 @@ alter table line_items
<sect2 id="example-mappings-composite-key-manytomany">
<title>Many-to-many with shared composite key attribute</title>
<programlisting><![CDATA[<class name="User" table="`User`">
<programlisting role="XML"><![CDATA[<class name="User" table="`User`">
<composite-id>
<key-property name="name"/>
<key-property name="org"/>
@ -575,7 +575,7 @@ alter table line_items
<sect2 id="example-mappings-content-discrimination">
<title>Content based discrimination</title>
<programlisting><![CDATA[<class name="Person"
<programlisting role="XML"><![CDATA[<class name="Person"
discriminator-value="P">
<id name="id"
@ -629,7 +629,7 @@ alter table line_items
<sect2 id="example-mappings-association-alternatekeys" revision="2">
<title>Associations on alternate keys</title>
<programlisting><![CDATA[<class name="Person">
<programlisting role="XML"><![CDATA[<class name="Person">
<id name="id">
<generator class="hilo"/>

View File

@ -92,7 +92,7 @@
<literal>Parent</literal> to <literal>Child</literal>.
</para>
<programlisting><![CDATA[<set name="children">
<programlisting role="XML"><![CDATA[<set name="children">
<key column="parent_id"/>
<one-to-many class="Child"/>
</set>]]></programlisting>
@ -101,7 +101,7 @@
If we were to execute the following code:
</para>
<programlisting><![CDATA[Parent p = .....;
<programlisting role="JAVA"><![CDATA[Parent p = .....;
Child c = new Child();
p.getChildren().add(c);
session.save(c);
@ -129,7 +129,7 @@ session.flush();]]></programlisting>
<literal>not-null="true"</literal> in the collection mapping:
</para>
<programlisting><![CDATA[<set name="children">
<programlisting role="XML"><![CDATA[<set name="children">
<key column="parent_id" not-null="true"/>
<one-to-many class="Child"/>
</set>]]></programlisting>
@ -144,7 +144,7 @@ session.flush();]]></programlisting>
solution is to make the link part of the <literal>Child</literal> mapping.
</para>
<programlisting><![CDATA[<many-to-one name="parent" column="parent_id" not-null="true"/>]]></programlisting>
<programlisting role="XML"><![CDATA[<many-to-one name="parent" column="parent_id" not-null="true"/>]]></programlisting>
<para>
You also need to add the <literal>parent</literal> property to the <literal>Child</literal> class.
@ -155,7 +155,7 @@ session.flush();]]></programlisting>
not to update the link. We use the <literal>inverse</literal> attribute to do this:
</para>
<programlisting><![CDATA[<set name="children" inverse="true">
<programlisting role="XML"><![CDATA[<set name="children" inverse="true">
<key column="parent_id"/>
<one-to-many class="Child"/>
</set>]]></programlisting>
@ -164,7 +164,7 @@ session.flush();]]></programlisting>
The following code would be used to add a new <literal>Child</literal>:
</para>
<programlisting><![CDATA[Parent p = (Parent) session.load(Parent.class, pid);
<programlisting role="JAVA"><![CDATA[Parent p = (Parent) session.load(Parent.class, pid);
Child c = new Child();
c.setParent(p);
p.getChildren().add(c);
@ -180,7 +180,7 @@ session.flush();]]></programlisting>
<literal>Parent</literal>.
</para>
<programlisting><![CDATA[public void addChild(Child c) {
<programlisting role="JAVA"><![CDATA[public void addChild(Child c) {
c.setParent(this);
children.add(c);
}]]></programlisting>
@ -189,7 +189,7 @@ session.flush();]]></programlisting>
The code to add a <literal>Child</literal> looks like this:
</para>
<programlisting><![CDATA[Parent p = (Parent) session.load(Parent.class, pid);
<programlisting role="JAVA"><![CDATA[Parent p = (Parent) session.load(Parent.class, pid);
Child c = new Child();
p.addChild(c);
session.save(c);
@ -205,7 +205,7 @@ session.flush();]]></programlisting>
using cascades.
</para>
<programlisting><![CDATA[<set name="children" inverse="true" cascade="all">
<programlisting role="XML"><![CDATA[<set name="children" inverse="true" cascade="all">
<key column="parent_id"/>
<one-to-many class="Child"/>
</set>]]></programlisting>
@ -214,7 +214,7 @@ session.flush();]]></programlisting>
This simplifies the code above to:
</para>
<programlisting><![CDATA[Parent p = (Parent) session.load(Parent.class, pid);
<programlisting role="JAVA"><![CDATA[Parent p = (Parent) session.load(Parent.class, pid);
Child c = new Child();
p.addChild(c);
session.flush();]]></programlisting>
@ -224,7 +224,7 @@ session.flush();]]></programlisting>
The following removes <literal>p</literal> and all its children from the database.
</para>
<programlisting><![CDATA[Parent p = (Parent) session.load(Parent.class, pid);
<programlisting role="JAVA"><![CDATA[Parent p = (Parent) session.load(Parent.class, pid);
session.delete(p);
session.flush();]]></programlisting>
@ -232,7 +232,7 @@ session.flush();]]></programlisting>
However, the following code:
</para>
<programlisting><![CDATA[Parent p = (Parent) session.load(Parent.class, pid);
<programlisting role="JAVA"><![CDATA[Parent p = (Parent) session.load(Parent.class, pid);
Child c = (Child) p.getChildren().iterator().next();
p.getChildren().remove(c);
c.setParent(null);
@ -244,7 +244,7 @@ session.flush();]]></programlisting>
<literal>delete()</literal> the <literal>Child</literal>.
</para>
<programlisting><![CDATA[Parent p = (Parent) session.load(Parent.class, pid);
<programlisting role="JAVA"><![CDATA[Parent p = (Parent) session.load(Parent.class, pid);
Child c = (Child) p.getChildren().iterator().next();
p.getChildren().remove(c);
session.delete(c);
@ -256,7 +256,7 @@ session.flush();]]></programlisting>
use <literal>cascade="all-delete-orphan"</literal>.
</para>
<programlisting><![CDATA[<set name="children" inverse="true" cascade="all-delete-orphan">
<programlisting role="XML"><![CDATA[<set name="children" inverse="true" cascade="all-delete-orphan">
<key column="parent_id"/>
<one-to-many class="Child"/>
</set>]]></programlisting>
@ -290,7 +290,7 @@ session.flush();]]></programlisting>
<literal>newChild</literal>:
</para>
<programlisting><![CDATA[//parent and child were both loaded in a previous session
<programlisting role="JAVA"><![CDATA[//parent and child were both loaded in a previous session
parent.addChild(child);
Child newChild = new Child();
parent.addChild(newChild);

View File

@ -37,7 +37,7 @@
relationship, but we will use an ordered bag, instead of a set:
</para>
<programlisting><![CDATA[package eg;
<programlisting role="JAVA"><![CDATA[package eg;
import java.util.List;
@ -66,7 +66,7 @@ public class Blog {
}
}]]></programlisting>
<programlisting><![CDATA[package eg;
<programlisting role="JAVA"><![CDATA[package eg;
import java.text.DateFormat;
import java.util.Calendar;
@ -119,7 +119,7 @@ public class BlogItem {
The XML mappings are now straightforward. For example:
</para>
<programlisting><![CDATA[<?xml version="1.0"?>
<programlisting role="XML"><![CDATA[<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
@ -159,7 +159,7 @@ public class BlogItem {
</hibernate-mapping>]]></programlisting>
<programlisting><![CDATA[<?xml version="1.0"?>
<programlisting role="XML"><![CDATA[<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
@ -213,7 +213,7 @@ public class BlogItem {
we can do with these classes using Hibernate:
</para>
<programlisting><![CDATA[package eg;
<programlisting role="JAVA"><![CDATA[package eg;
import java.util.ArrayList;
import java.util.Calendar;

View File

@ -53,7 +53,7 @@
within a <literal>&lt;hibernate-mapping/&gt;</literal> element:
</para>
<programlisting><![CDATA[<filter-def name="myFilter">
<programlisting role="XML"><![CDATA[<filter-def name="myFilter">
<filter-param name="myFilterParam" type="string"/>
</filter-def>]]></programlisting>
@ -61,7 +61,7 @@
This filter can then be attached to a class:
</para>
<programlisting><![CDATA[<class name="myClass" ...>
<programlisting role="XML"><![CDATA[<class name="myClass" ...>
...
<filter name="myFilter" condition=":myFilterParam = MY_FILTERED_COLUMN"/>
</class>]]></programlisting>
@ -70,7 +70,7 @@
Or, to a collection:
</para>
<programlisting><![CDATA[<set ...>
<programlisting role="XML"><![CDATA[<set ...>
<filter name="myFilter" condition=":myFilterParam = MY_FILTERED_COLUMN"/>
</set>]]></programlisting>
@ -87,7 +87,7 @@
look like this:
</para>
<programlisting><![CDATA[session.enableFilter("myFilter").setParameter("myFilterParam", "some-value");]]></programlisting>
<programlisting role="JAVA"><![CDATA[session.enableFilter("myFilter").setParameter("myFilterParam", "some-value");]]></programlisting>
<para>
Methods on the org.hibernate.Filter interface do allow the method-chaining common to much of Hibernate.
@ -97,7 +97,7 @@
The following is a full example, using temporal data with an effective record date pattern:
</para>
<programlisting><![CDATA[<filter-def name="effectiveDate">
<programlisting role="XML"><![CDATA[<filter-def name="effectiveDate">
<filter-param name="asOfDate" type="date"/>
</filter-def>
@ -130,7 +130,7 @@
enable the filter on the session prior to retrieving employee data:
</para>
<programlisting><![CDATA[Session session = ...;
<programlisting role="JAVA"><![CDATA[Session session = ...;
session.enableFilter("effectiveDate").setParameter("asOfDate", new Date());
List results = session.createQuery("from Employee as e where e.salary > :targetSalary")
.setLong("targetSalary", new Long(1000000))
@ -157,7 +157,7 @@ List results = session.createQuery("from Employee as e where e.salary > :targetS
allows you to definine a default condition, either as an attribute or CDATA:
</para>
<programlisting><![CDATA[<filter-def name="myFilter" condition="abc > xyz">...</filter-def>
<programlisting role="XML"><![CDATA[<filter-def name="myFilter" condition="abc > xyz">...</filter-def>
<filter-def name="myOtherFilter">abc=xyz</filter-def>]]></programlisting>
<para>

View File

@ -91,7 +91,7 @@
before subclasses.
</para>
<programlisting><![CDATA[
<programlisting role="XML"><![CDATA[
<hibernate-mapping>
<subclass name="DomesticCat" extends="Cat" discriminator-value="D">
<property name="name" type="string"/>
@ -109,7 +109,7 @@
display in the following way:
</para>
<programlisting><![CDATA[<class name="Payment" table="PAYMENT">
<programlisting role="XML"><![CDATA[<class name="Payment" table="PAYMENT">
<id name="id" type="long" column="PAYMENT_ID">
<generator class="native"/>
</id>
@ -143,7 +143,7 @@
A table per subclass mapping looks like this:
</para>
<programlisting><![CDATA[<class name="Payment" table="PAYMENT">
<programlisting role="XML"><![CDATA[<class name="Payment" table="PAYMENT">
<id name="id" type="long" column="PAYMENT_ID">
<generator class="native"/>
</id>
@ -187,7 +187,7 @@
<literal>&lt;join&gt;</literal>, as follows:
</para>
<programlisting><![CDATA[<class name="Payment" table="PAYMENT">
<programlisting role="XML"><![CDATA[<class name="Payment" table="PAYMENT">
<id name="id" type="long" column="PAYMENT_ID">
<generator class="native"/>
</id>
@ -231,7 +231,7 @@
using the following approach:
</para>
<programlisting><![CDATA[<class name="Payment" table="PAYMENT">
<programlisting role="XML"><![CDATA[<class name="Payment" table="PAYMENT">
<id name="id" type="long" column="PAYMENT_ID">
<generator class="native"/>
</id>
@ -258,7 +258,7 @@
<literal>&lt;many-to-one&gt;</literal>.
</para>
<programlisting><![CDATA[<many-to-one name="payment" column="PAYMENT_ID" class="Payment"/>]]></programlisting>
<programlisting role="XML"><![CDATA[<many-to-one name="payment" column="PAYMENT_ID" class="Payment"/>]]></programlisting>
</sect2>
@ -270,7 +270,7 @@
strategy. First, you can use <literal>&lt;union-subclass&gt;</literal>.
</para>
<programlisting><![CDATA[<class name="Payment">
<programlisting role="XML"><![CDATA[<class name="Payment">
<id name="id" type="long" column="PAYMENT_ID">
<generator class="sequence"/>
</id>
@ -318,7 +318,7 @@
An alternative approach is to make use of implicit polymorphism:
</para>
<programlisting><![CDATA[<class name="CreditCardPayment" table="CREDIT_PAYMENT">
<programlisting role="XML"><![CDATA[<class name="CreditCardPayment" table="CREDIT_PAYMENT">
<id name="id" type="long" column="CREDIT_PAYMENT_ID">
<generator class="native"/>
</id>
@ -362,7 +362,7 @@
is usually mapped using <literal>&lt;any&gt;</literal>.
</para>
<programlisting><![CDATA[<any name="payment" meta-type="string" id-type="long">
<programlisting role="XML"><![CDATA[<any name="payment" meta-type="string" id-type="long">
<meta-value value="CREDIT" class="CreditCardPayment"/>
<meta-value value="CASH" class="CashPayment"/>
<meta-value value="CHEQUE" class="ChequePayment"/>
@ -383,7 +383,7 @@
queries against the <literal>Payment</literal> interface.
</para>
<programlisting><![CDATA[<class name="CreditCardPayment" table="CREDIT_PAYMENT">
<programlisting role="XML"><![CDATA[<class name="CreditCardPayment" table="CREDIT_PAYMENT">
<id name="id" type="long" column="CREDIT_PAYMENT_ID">
<generator class="native"/>
</id>

View File

@ -161,7 +161,7 @@
in an exception. For example:
</para>
<programlisting><![CDATA[s = sessions.openSession();
<programlisting role="JAVA"><![CDATA[s = sessions.openSession();
Transaction tx = s.beginTransaction();
User u = (User) s.createQuery("from User u where u.name=:userName")
@ -208,13 +208,13 @@ Integer accessLevel = (Integer) permissions.get("accounts"); // Error!]]></prog
so we might want to enable join fetching in the mapping document:
</para>
<programlisting><![CDATA[<set name="permissions"
<programlisting role="XML"><![CDATA[<set name="permissions"
fetch="join">
<key column="userId"/>
<one-to-many class="Permission"/>
</set]]></programlisting>
<programlisting><![CDATA[<many-to-one name="mother" class="Cat" fetch="join"/>]]></programlisting>
<programlisting role="XML"><![CDATA[<many-to-one name="mother" class="Cat" fetch="join"/>]]></programlisting>
<para>
The <literal>fetch</literal> strategy defined in the mapping document affects:
@ -264,7 +264,7 @@ Integer accessLevel = (Integer) permissions.get("accounts"); // Error!]]></prog
<literal>Criteria</literal> query. For example:
</para>
<programlisting><![CDATA[User user = (User) session.createCriteria(User.class)
<programlisting role="JAVA"><![CDATA[User user = (User) session.createCriteria(User.class)
.setFetchMode("permissions", FetchMode.JOIN)
.add( Restrictions.idEq(userId) )
.uniqueResult();]]></programlisting>
@ -308,7 +308,7 @@ Integer accessLevel = (Integer) permissions.get("accounts"); // Error!]]></prog
There are potential problems to note when extending this approach to polymorphic classes.For example:
</para>
<programlisting><![CDATA[<class name="Cat" proxy="Cat">
<programlisting role="XML"><![CDATA[<class name="Cat" proxy="Cat">
......
<subclass name="DomesticCat">
.....
@ -321,7 +321,7 @@ Integer accessLevel = (Integer) permissions.get("accounts"); // Error!]]></prog
instance of <literal>DomesticCat</literal>:
</para>
<programlisting><![CDATA[Cat cat = (Cat) session.load(Cat.class, id); // instantiate a proxy (does not hit the db)
<programlisting role="JAVA"><![CDATA[Cat cat = (Cat) session.load(Cat.class, id); // instantiate a proxy (does not hit the db)
if ( cat.isDomesticCat() ) { // hit the db to initialize the proxy
DomesticCat dc = (DomesticCat) cat; // Error!
....
@ -331,7 +331,7 @@ if ( cat.isDomesticCat() ) { // hit the db to initialize the pr
Secondly, it is possible to break proxy <literal>==</literal>:
</para>
<programlisting><![CDATA[Cat cat = (Cat) session.load(Cat.class, id); // instantiate a Cat proxy
<programlisting role="JAVA"><![CDATA[Cat cat = (Cat) session.load(Cat.class, id); // instantiate a Cat proxy
DomesticCat dc =
(DomesticCat) session.load(DomesticCat.class, id); // acquire new DomesticCat proxy!
System.out.println(cat==dc); // false]]></programlisting>
@ -341,7 +341,7 @@ System.out.println(cat==dc); // false]]></programlist
to different proxy objects, the underlying instance will still be the same object:
</para>
<programlisting><![CDATA[cat.setWeight(11.0); // hit the db to initialize the proxy
<programlisting role="JAVA"><![CDATA[cat.setWeight(11.0); // hit the db to initialize the proxy
System.out.println( dc.getWeight() ); // 11.0]]></programlisting>
<para>
@ -363,7 +363,7 @@ System.out.println( dc.getWeight() ); // 11.0]]></programlisting>
implements the interface <literal>DomesticCat</literal>. For example:
</para>
<programlisting><![CDATA[<class name="CatImpl" proxy="Cat">
<programlisting role="XML"><![CDATA[<class name="CatImpl" proxy="Cat">
......
<subclass name="DomesticCatImpl" proxy="DomesticCat">
.....
@ -375,7 +375,7 @@ System.out.println( dc.getWeight() ); // 11.0]]></programlisting>
by <literal>load()</literal> or <literal>iterate()</literal>.
</para>
<programlisting><![CDATA[Cat cat = (Cat) session.load(CatImpl.class, catid);
<programlisting role="JAVA"><![CDATA[Cat cat = (Cat) session.load(CatImpl.class, catid);
Iterator iter = session.createQuery("from CatImpl as cat where cat.name='fritz'").iterate();
Cat fritz = (Cat) iter.next();]]></programlisting>
@ -512,14 +512,14 @@ Cat fritz = (Cat) iter.next();]]></programlisting>
You can use a collection filter to get the size of a collection without initializing it:
</para>
<programlisting><![CDATA[( (Integer) s.createFilter( collection, "select count(*)" ).list().get(0) ).intValue()]]></programlisting>
<programlisting role="JAVA"><![CDATA[( (Integer) s.createFilter( collection, "select count(*)" ).list().get(0) ).intValue()]]></programlisting>
<para>
The <literal>createFilter()</literal> method is also used to efficiently retrieve subsets
of a collection without needing to initialize the whole collection:
</para>
<programlisting><![CDATA[s.createFilter( lazyCollection, "").setFirstResult(0).setMaxResults(10).list();]]></programlisting>
<programlisting role="JAVA"><![CDATA[s.createFilter( lazyCollection, "").setFirstResult(0).setMaxResults(10).list();]]></programlisting>
</sect2>
@ -542,7 +542,7 @@ Cat fritz = (Cat) iter.next();]]></programlisting>
behavior by specifying a <literal>batch-size</literal> in the mapping of <literal>Person</literal>:
</para>
<programlisting><![CDATA[<class name="Person" batch-size="10">...</class>]]></programlisting>
<programlisting role="XML"><![CDATA[<class name="Person" batch-size="10">...</class>]]></programlisting>
<para>
Hibernate will now execute only three queries: the pattern is 10, 10, 5.
@ -557,7 +557,7 @@ Cat fritz = (Cat) iter.next();]]></programlisting>
collections:
</para>
<programlisting><![CDATA[<class name="Person">
<programlisting role="XML"><![CDATA[<class name="Person">
<set name="cats" batch-size="3">
...
</set>
@ -605,7 +605,7 @@ Cat fritz = (Cat) iter.next();]]></programlisting>
So what does that mean? Well lets explain that by way of an example. Say we have
the following mappings:
</para>
<programlisting><![CDATA[<hibernate-mapping>
<programlisting role="XML"><![CDATA[<hibernate-mapping>
<class name="Customer">
...
<set name="orders" inverse="true">
@ -625,7 +625,7 @@ Cat fritz = (Cat) iter.next();]]></programlisting>
to use "dynamic fetching" strategies via an HQL or criteria queries. But another option is
to use a fetch profile to achieve that. Just add the following to your mapping:
</para>
<programlisting><![CDATA[<hibernate-mapping>
<programlisting role="XML"><![CDATA[<hibernate-mapping>
...
<fetch-profile name="customer-with-orders">
<fetch entity="Customer" association="orders" style="join"/>
@ -634,7 +634,7 @@ Cat fritz = (Cat) iter.next();]]></programlisting>
<para>
or even:
</para>
<programlisting><![CDATA[<hibernate-mapping>
<programlisting role="XML"><![CDATA[<hibernate-mapping>
<class name="Customer">
...
<fetch-profile name="customer-with-orders">
@ -646,7 +646,7 @@ Cat fritz = (Cat) iter.next();]]></programlisting>
<para>
Now the following code will actually load both the customer <emphasis>and their orders</emphasis>:
</para>
<programlisting><![CDATA[
<programlisting role="JAVA"><![CDATA[
Session session = ...;
session.enableFetchProfile( "customer-with-orders" ); // name matches from mapping
Customer customer = (Customer) session.get( Customer.class, customerId );
@ -676,7 +676,7 @@ Cat fritz = (Cat) iter.next();]]></programlisting>
particular property mappings:
</para>
<programlisting><![CDATA[<class name="Document">
<programlisting role="XML"><![CDATA[<class name="Document">
<id name="id">
<generator class="native"/>
</id>
@ -695,7 +695,7 @@ Cat fritz = (Cat) iter.next();]]></programlisting>
For bytecode instrumentation, use the following Ant task:
</para>
<programlisting><![CDATA[<target name="instrument" depends="compile">
<programlisting role="XML"><![CDATA[<target name="instrument" depends="compile">
<taskdef name="instrument" classname="org.hibernate.tool.instrument.InstrumentTask">
<classpath path="${jar.path}"/>
<classpath path="${classes.dir}"/>
@ -823,7 +823,7 @@ Cat fritz = (Cat) iter.next();]]></programlisting>
<area id="cache2" coords="3 70"/>
<area id="cache3" coords="4 70"/>
</areaspec>
<programlisting><![CDATA[<cache
<programlisting role="XML"><![CDATA[<cache
usage="transactional|read-write|nonstrict-read-write|read-only"
region="RegionName"
include="all|non-lazy"
@ -876,7 +876,7 @@ Cat fritz = (Cat) iter.next();]]></programlisting>
strategy. It is even safe for use in a cluster.
</para>
<programlisting><![CDATA[<class name="eg.Immutable" mutable="false">
<programlisting role="XML"><![CDATA[<class name="eg.Immutable" mutable="false">
<cache usage="read-only"/>
....
</class>]]></programlisting>
@ -898,7 +898,7 @@ Cat fritz = (Cat) iter.next();]]></programlisting>
supports locking. The built-in cache providers <emphasis>do not</emphasis> support locking.
</para>
<programlisting><![CDATA[<class name="eg.Cat" .... >
<programlisting role="XML"><![CDATA[<class name="eg.Cat" .... >
<cache usage="read-write"/>
....
<set name="kittens" ... >
@ -1033,7 +1033,7 @@ Cat fritz = (Cat) iter.next();]]></programlisting>
from the first-level cache.
</para>
<programlisting><![CDATA[ScrollableResult cats = sess.createQuery("from Cat as cat").scroll(); //a huge result set
<programlisting role="JAVA"><![CDATA[ScrollableResult cats = sess.createQuery("from Cat as cat").scroll(); //a huge result set
while ( cats.next() ) {
Cat cat = (Cat) cats.get(0);
doSomethingWithACat(cat);
@ -1055,7 +1055,7 @@ while ( cats.next() ) {
role.
</para>
<programlisting><![CDATA[sessionFactory.evict(Cat.class, catId); //evict a particular Cat
<programlisting role="JAVA"><![CDATA[sessionFactory.evict(Cat.class, catId); //evict a particular Cat
sessionFactory.evict(Cat.class); //evict all Cats
sessionFactory.evictCollection("Cat.kittens", catId); //evict a particular collection of kittens
sessionFactory.evictCollection("Cat.kittens"); //evict all kitten collections]]></programlisting>
@ -1097,7 +1097,7 @@ sessionFactory.evictCollection("Cat.kittens"); //evict all kitten collections]]>
API:
</para>
<programlisting><![CDATA[Map cacheEntries = sessionFactory.getStatistics()
<programlisting role="JAVA"><![CDATA[Map cacheEntries = sessionFactory.getStatistics()
.getSecondLevelCacheStatistics(regionName)
.getEntries();]]></programlisting>
@ -1144,7 +1144,7 @@ hibernate.cache.use_structured_entries true]]></programlisting>
<literal>Query.setCacheRegion()</literal>.
</para>
<programlisting><![CDATA[List blogs = sess.createQuery("from Blog blog where blog.blogger = :blogger")
<programlisting role="JAVA"><![CDATA[List blogs = sess.createQuery("from Blog blog where blog.blogger = :blogger")
.setEntity("blogger", blogger)
.setMaxResults(15)
.setCacheable(true)
@ -1298,7 +1298,7 @@ hibernate.cache.use_structured_entries true]]></programlisting>
make the following common code much faster:
</para>
<programlisting><![CDATA[Parent p = (Parent) sess.load(Parent.class, id);
<programlisting role="JAVA"><![CDATA[Parent p = (Parent) sess.load(Parent.class, id);
Child c = new Child();
c.setParent(p);
p.getChildren().add(c); //no need to fetch the collection!
@ -1382,7 +1382,7 @@ sess.flush();]]></programlisting>
minimalistic configuration examples:
</para>
<programlisting><![CDATA[// MBean service registration for a specific SessionFactory
<programlisting role="JAVA"><![CDATA[// MBean service registration for a specific SessionFactory
Hashtable tb = new Hashtable();
tb.put("type", "statistics");
tb.put("sessionFactory", "myFinancialApp");
@ -1393,7 +1393,7 @@ stats.setSessionFactory(sessionFactory); // Bind the stats to a SessionFactory
server.registerMBean(stats, on); // Register the Mbean on the server]]></programlisting>
<programlisting><![CDATA[// MBean service registration for all SessionFactory's
<programlisting role="JAVA"><![CDATA[// MBean service registration for all SessionFactory's
Hashtable tb = new Hashtable();
tb.put("type", "statistics");
tb.put("sessionFactory", "all");
@ -1475,7 +1475,7 @@ server.registerMBean(stats, on); // Register the MBean on the server]]></program
code is a simple example:
</para>
<programlisting><![CDATA[Statistics stats = HibernateUtil.sessionFactory.getStatistics();
<programlisting role="JAVA"><![CDATA[Statistics stats = HibernateUtil.sessionFactory.getStatistics();
double queryCacheHitCount = stats.getQueryCacheHitCount();
double queryCacheMissCount = stats.getQueryCacheMissCount();

View File

@ -50,7 +50,7 @@
Most Java applications require a persistent class representing felines. For example:
</para>
<programlisting><![CDATA[package eg;
<programlisting role="JAVA"><![CDATA[package eg;
import java.util.Set;
import java.util.Date;
@ -243,7 +243,7 @@ public class Cat {
identifier property from the superclass, <literal>Cat</literal>. For example:
</para>
<programlisting><![CDATA[package eg;
<programlisting role="JAVA"><![CDATA[package eg;
public class DomesticCat extends Cat {
private String name;
@ -309,7 +309,7 @@ public class DomesticCat extends Cat {
<emphasis>natural</emphasis> candidate key):
</para>
<programlisting><![CDATA[public class Cat {
<programlisting role="JAVA"><![CDATA[public class Cat {
...
public boolean equals(Object other) {
@ -374,7 +374,7 @@ public class DomesticCat extends Cat {
instead of, or in addition to, a class name:
</para>
<programlisting><![CDATA[<hibernate-mapping>
<programlisting role="XML"><![CDATA[<hibernate-mapping>
<class entity-name="Customer">
@ -421,7 +421,7 @@ public class DomesticCat extends Cat {
<literal>Map</literal>s of <literal>Map</literal>s:
</para>
<programlisting><![CDATA[Session s = openSession();
<programlisting role="JAVA"><![CDATA[Session s = openSession();
Transaction tx = s.beginTransaction();
Session s = openSession();
@ -456,7 +456,7 @@ s.close();]]></programlisting>
basis:
</para>
<programlisting><![CDATA[Session dynamicSession = pojoSession.getSession(EntityMode.MAP);
<programlisting role="JAVA"><![CDATA[Session dynamicSession = pojoSession.getSession(EntityMode.MAP);
// Create a customer
Map david = new HashMap();
@ -517,7 +517,7 @@ dynamicSession.close()
are meant to manage. Going back to the example of our customer entity:
</para>
<programlisting><![CDATA[<hibernate-mapping>
<programlisting role="XML"><![CDATA[<hibernate-mapping>
<class entity-name="Customer">
<!--
Override the dynamic-map entity-mode
@ -572,7 +572,7 @@ public class CustomMapTuplizerImpl
for illustration.
</para>
<programlisting>
<programlisting role="JAVA">
/**
* A very trivial JDK Proxy InvocationHandler implementation where we proxy an interface as
* the domain model and simply store persistent state in an internal Map. This is an extremely

View File

@ -73,7 +73,7 @@
Starting with version 3.3, Hibernate has a fare more powerful way to automatically determine
which dialect to should be used by relying on a series of delegates which implement the
<interfacename>org.hibernate.dialect.resolver.DialectResolver</interfacename> which defines only a
single method:<programlisting><![CDATA[public Dialect resolveDialect(DatabaseMetaData metaData) throws JDBCConnectionException]]></programlisting>.
single method:<programlisting role="JAVA"><![CDATA[public Dialect resolveDialect(DatabaseMetaData metaData) throws JDBCConnectionException]]></programlisting>.
The basic contract here is that if the resolver 'understands' the given database metadata then
it returns the corresponding Dialect; if not it returns null and the process continues to the next
resolver. The signature also identifies <exceptionname>org.hibernate.exception.JDBCConnectionException</exceptionname>

View File

@ -41,7 +41,7 @@
<literal>Criteria</literal> instances.
</para>
<programlisting><![CDATA[Criteria crit = sess.createCriteria(Cat.class);
<programlisting role="JAVA"><![CDATA[Criteria crit = sess.createCriteria(Cat.class);
crit.setMaxResults(50);
List cats = crit.list();]]></programlisting>
@ -58,7 +58,7 @@ List cats = crit.list();]]></programlisting>
<literal>Criterion</literal> types.
</para>
<programlisting><![CDATA[List cats = sess.createCriteria(Cat.class)
<programlisting role="JAVA"><![CDATA[List cats = sess.createCriteria(Cat.class)
.add( Restrictions.like("name", "Fritz%") )
.add( Restrictions.between("weight", minWeight, maxWeight) )
.list();]]></programlisting>
@ -67,7 +67,7 @@ List cats = crit.list();]]></programlisting>
Restrictions can be grouped logically.
</para>
<programlisting><![CDATA[List cats = sess.createCriteria(Cat.class)
<programlisting role="JAVA"><![CDATA[List cats = sess.createCriteria(Cat.class)
.add( Restrictions.like("name", "Fritz%") )
.add( Restrictions.or(
Restrictions.eq( "age", new Integer(0) ),
@ -75,7 +75,7 @@ List cats = crit.list();]]></programlisting>
) )
.list();]]></programlisting>
<programlisting><![CDATA[List cats = sess.createCriteria(Cat.class)
<programlisting role="JAVA"><![CDATA[List cats = sess.createCriteria(Cat.class)
.add( Restrictions.in( "name", new String[] { "Fritz", "Izi", "Pk" } ) )
.add( Restrictions.disjunction()
.add( Restrictions.isNull("age") )
@ -90,7 +90,7 @@ List cats = crit.list();]]></programlisting>
subclasses). One of the most useful allows you to specify SQL directly.
</para>
<programlisting><![CDATA[List cats = sess.createCriteria(Cat.class)
<programlisting role="JAVA"><![CDATA[List cats = sess.createCriteria(Cat.class)
.add( Restrictions.sqlRestriction("lower({alias}.name) like lower(?)", "Fritz%", Hibernate.STRING) )
.list();]]></programlisting>
@ -105,7 +105,7 @@ List cats = crit.list();]]></programlisting>
by calling <literal>Property.forName()</literal>:
</para>
<programlisting><![CDATA[
<programlisting role="JAVA"><![CDATA[
Property age = Property.forName("age");
List cats = sess.createCriteria(Cat.class)
.add( Restrictions.disjunction()
@ -126,14 +126,14 @@ List cats = sess.createCriteria(Cat.class)
You can order the results using <literal>org.hibernate.criterion.Order</literal>.
</para>
<programlisting><![CDATA[List cats = sess.createCriteria(Cat.class)
<programlisting role="JAVA"><![CDATA[List cats = sess.createCriteria(Cat.class)
.add( Restrictions.like("name", "F%")
.addOrder( Order.asc("name") )
.addOrder( Order.desc("age") )
.setMaxResults(50)
.list();]]></programlisting>
<programlisting><![CDATA[List cats = sess.createCriteria(Cat.class)
<programlisting role="JAVA"><![CDATA[List cats = sess.createCriteria(Cat.class)
.add( Property.forName("name").like("F%") )
.addOrder( Property.forName("name").asc() )
.addOrder( Property.forName("age").desc() )
@ -150,7 +150,7 @@ List cats = sess.createCriteria(Cat.class)
associations using <literal>createCriteria()</literal> you can specify constraints upon related entities:
</para>
<programlisting><![CDATA[List cats = sess.createCriteria(Cat.class)
<programlisting role="JAVA"><![CDATA[List cats = sess.createCriteria(Cat.class)
.add( Restrictions.like("name", "F%") )
.createCriteria("kittens")
.add( Restrictions.like("name", "F%") )
@ -166,7 +166,7 @@ List cats = sess.createCriteria(Cat.class)
There is also an alternate form that is useful in certain circumstances:
</para>
<programlisting><![CDATA[List cats = sess.createCriteria(Cat.class)
<programlisting role="JAVA"><![CDATA[List cats = sess.createCriteria(Cat.class)
.createAlias("kittens", "kt")
.createAlias("mate", "mt")
.add( Restrictions.eqProperty("kt.name", "mt.name") )
@ -184,7 +184,7 @@ List cats = sess.createCriteria(Cat.class)
criteria, you must use a <literal>ResultTransformer</literal>.
</para>
<programlisting><![CDATA[List cats = sess.createCriteria(Cat.class)
<programlisting role="JAVA"><![CDATA[List cats = sess.createCriteria(Cat.class)
.createCriteria("kittens", "kt")
.add( Restrictions.eq("name", "F%") )
.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP)
@ -206,7 +206,7 @@ while ( iter.hasNext() ) {
<literal>setFetchMode()</literal>.
</para>
<programlisting><![CDATA[List cats = sess.createCriteria(Cat.class)
<programlisting role="JAVA"><![CDATA[List cats = sess.createCriteria(Cat.class)
.add( Restrictions.like("name", "Fritz%") )
.setFetchMode("mate", FetchMode.EAGER)
.setFetchMode("kittens", FetchMode.EAGER)
@ -227,7 +227,7 @@ while ( iter.hasNext() ) {
you to construct a query criterion from a given instance.
</para>
<programlisting><![CDATA[Cat cat = new Cat();
<programlisting role="JAVA"><![CDATA[Cat cat = new Cat();
cat.setSex('F');
cat.setColor(Color.BLACK);
List results = session.createCriteria(Cat.class)
@ -243,7 +243,7 @@ List results = session.createCriteria(Cat.class)
You can adjust how the <literal>Example</literal> is applied.
</para>
<programlisting><![CDATA[Example example = Example.create(cat)
<programlisting role="JAVA"><![CDATA[Example example = Example.create(cat)
.excludeZeroes() //exclude zero valued properties
.excludeProperty("color") //exclude the property named "color"
.ignoreCase() //perform case insensitive string comparisons
@ -256,7 +256,7 @@ List results = session.createCriteria(Cat.class)
You can even use examples to place criteria upon associated objects.
</para>
<programlisting><![CDATA[List results = session.createCriteria(Cat.class)
<programlisting role="JAVA"><![CDATA[List results = session.createCriteria(Cat.class)
.add( Example.create(cat) )
.createCriteria("mate")
.add( Example.create( cat.getMate() ) )
@ -272,12 +272,12 @@ List results = session.createCriteria(Cat.class)
projection to a query by calling <literal>setProjection()</literal>.
</para>
<programlisting><![CDATA[List results = session.createCriteria(Cat.class)
<programlisting role="JAVA"><![CDATA[List results = session.createCriteria(Cat.class)
.setProjection( Projections.rowCount() )
.add( Restrictions.eq("color", Color.BLACK) )
.list();]]></programlisting>
<programlisting><![CDATA[List results = session.createCriteria(Cat.class)
<programlisting role="JAVA"><![CDATA[List results = session.createCriteria(Cat.class)
.setProjection( Projections.projectionList()
.add( Projections.rowCount() )
.add( Projections.avg("weight") )
@ -298,12 +298,12 @@ List results = session.createCriteria(Cat.class)
do this:
</para>
<programlisting><![CDATA[List results = session.createCriteria(Cat.class)
<programlisting role="JAVA"><![CDATA[List results = session.createCriteria(Cat.class)
.setProjection( Projections.alias( Projections.groupProperty("color"), "colr" ) )
.addOrder( Order.asc("colr") )
.list();]]></programlisting>
<programlisting><![CDATA[List results = session.createCriteria(Cat.class)
<programlisting role="JAVA"><![CDATA[List results = session.createCriteria(Cat.class)
.setProjection( Projections.groupProperty("color").as("colr") )
.addOrder( Order.asc("colr") )
.list();]]></programlisting>
@ -315,7 +315,7 @@ List results = session.createCriteria(Cat.class)
projection list:
</para>
<programlisting><![CDATA[List results = session.createCriteria(Cat.class)
<programlisting role="JAVA"><![CDATA[List results = session.createCriteria(Cat.class)
.setProjection( Projections.projectionList()
.add( Projections.rowCount(), "catCountByColor" )
.add( Projections.avg("weight"), "avgWeight" )
@ -326,7 +326,7 @@ List results = session.createCriteria(Cat.class)
.addOrder( Order.desc("avgWeight") )
.list();]]></programlisting>
<programlisting><![CDATA[List results = session.createCriteria(Domestic.class, "cat")
<programlisting role="JAVA"><![CDATA[List results = session.createCriteria(Domestic.class, "cat")
.createAlias("kittens", "kit")
.setProjection( Projections.projectionList()
.add( Projections.property("cat.name"), "catName" )
@ -340,12 +340,12 @@ List results = session.createCriteria(Cat.class)
You can also use <literal>Property.forName()</literal> to express projections:
</para>
<programlisting><![CDATA[List results = session.createCriteria(Cat.class)
<programlisting role="JAVA"><![CDATA[List results = session.createCriteria(Cat.class)
.setProjection( Property.forName("name") )
.add( Property.forName("color").eq(Color.BLACK) )
.list();]]></programlisting>
<programlisting><![CDATA[List results = session.createCriteria(Cat.class)
<programlisting role="JAVA"><![CDATA[List results = session.createCriteria(Cat.class)
.setProjection( Projections.projectionList()
.add( Projections.rowCount().as("catCountByColor") )
.add( Property.forName("weight").avg().as("avgWeight") )
@ -365,7 +365,7 @@ List results = session.createCriteria(Cat.class)
of a session and then execute it using an arbitrary <literal>Session</literal>.
</para>
<programlisting><![CDATA[DetachedCriteria query = DetachedCriteria.forClass(Cat.class)
<programlisting role="JAVA"><![CDATA[DetachedCriteria query = DetachedCriteria.forClass(Cat.class)
.add( Property.forName("sex").eq('F') );
Session session = ....;
@ -380,13 +380,13 @@ session.close();]]></programlisting>
<literal>Property</literal>.
</para>
<programlisting><![CDATA[DetachedCriteria avgWeight = DetachedCriteria.forClass(Cat.class)
<programlisting role="JAVA"><![CDATA[DetachedCriteria avgWeight = DetachedCriteria.forClass(Cat.class)
.setProjection( Property.forName("weight").avg() );
session.createCriteria(Cat.class)
.add( Property.forName("weight").gt(avgWeight) )
.list();]]></programlisting>
<programlisting><![CDATA[DetachedCriteria weights = DetachedCriteria.forClass(Cat.class)
<programlisting role="JAVA"><![CDATA[DetachedCriteria weights = DetachedCriteria.forClass(Cat.class)
.setProjection( Property.forName("weight") );
session.createCriteria(Cat.class)
.add( Subqueries.geAll("weight", weights) )
@ -396,7 +396,7 @@ session.createCriteria(Cat.class)
Correlated subqueries are also possible:
</para>
<programlisting><![CDATA[DetachedCriteria avgWeightForSex = DetachedCriteria.forClass(Cat.class, "cat2")
<programlisting role="JAVA"><![CDATA[DetachedCriteria avgWeightForSex = DetachedCriteria.forClass(Cat.class, "cat2")
.setProjection( Property.forName("weight").avg() )
.add( Property.forName("cat2.sex").eqProperty("cat.sex") );
session.createCriteria(Cat.class, "cat")
@ -425,7 +425,7 @@ session.createCriteria(Cat.class, "cat")
<literal>&lt;natural-id&gt;</literal> and enable use of the second-level cache.
</para>
<programlisting><![CDATA[<class name="User">
<programlisting role="XML"><![CDATA[<class name="User">
<cache usage="read-write"/>
<id name="id">
<generator class="increment"/>
@ -448,7 +448,7 @@ session.createCriteria(Cat.class, "cat")
the more efficient cache algorithm.
</para>
<programlisting><![CDATA[session.createCriteria(User.class)
<programlisting role="JAVA"><![CDATA[session.createCriteria(User.class)
.add( Restrictions.naturalId()
.set("name", "gavin")
.set("org", "hb")

View File

@ -1119,7 +1119,7 @@ order by account.type.sortOrder, account.accountNumber, payment.dueDate]]></prog
You can count the number of query results without returning them:
</para>
<programlisting><![CDATA[( (Integer) session.createQuery("select count(*) from ....").iterate().next() ).intValue()]]></programlisting>
<programlisting role="JAVA"><![CDATA[( (Integer) session.createQuery("select count(*) from ....").iterate().next() ).intValue()]]></programlisting>
<para>
To order a result by the size of a collection, use the following query:
@ -1164,7 +1164,7 @@ having count(msg) = 0]]></programlisting>
Properties of a JavaBean can be bound to named query parameters:
</para>
<programlisting><![CDATA[Query q = s.createQuery("from foo Foo as foo where foo.name=:name and foo.size=:size");
<programlisting role="JAVA"><![CDATA[Query q = s.createQuery("from foo Foo as foo where foo.name=:name and foo.size=:size");
q.setProperties(fooBean); // fooBean has getName() and getSize()
List foos = q.list();]]></programlisting>
@ -1172,7 +1172,7 @@ List foos = q.list();]]></programlisting>
Collections are pageable by using the <literal>Query</literal> interface with a filter:
</para>
<programlisting><![CDATA[Query q = s.createFilter( collection, "" ); // the trivial filter
<programlisting role="JAVA"><![CDATA[Query q = s.createFilter( collection, "" ); // the trivial filter
q.setMaxResults(PAGE_SIZE);
q.setFirstResult(PAGE_SIZE * pageNumber);
List page = q.list();]]></programlisting>
@ -1181,14 +1181,14 @@ List page = q.list();]]></programlisting>
Collection elements can be ordered or grouped using a query filter:
</para>
<programlisting><![CDATA[Collection orderedCollection = s.filter( collection, "order by this.amount" );
<programlisting role="JAVA"><![CDATA[Collection orderedCollection = s.filter( collection, "order by this.amount" );
Collection counts = s.filter( collection, "select this.type, count(this) group by this.type" );]]></programlisting>
<para>
You can find the size of a collection without initializing it:
</para>
<programlisting><![CDATA[( (Integer) session.createQuery("select count(*) from ....").iterate().next() ).intValue();]]></programlisting>
<programlisting role="JAVA"><![CDATA[( (Integer) session.createQuery("select count(*) from ....").iterate().next() ).intValue();]]></programlisting>
</sect1>

View File

@ -51,7 +51,7 @@
<para>The most basic SQL query is to get a list of scalars
(values).</para>
<programlisting><![CDATA[sess.createSQLQuery("SELECT * FROM CATS").list();
<programlisting role="JAVA"><![CDATA[sess.createSQLQuery("SELECT * FROM CATS").list();
sess.createSQLQuery("SELECT ID, NAME, BIRTHDATE FROM CATS").list();
]]></programlisting>
@ -64,7 +64,7 @@ sess.createSQLQuery("SELECT ID, NAME, BIRTHDATE FROM CATS").list();
<literal>ResultSetMetadata</literal>, or simply to be more explicit in
what is returned, one can use <literal>addScalar()</literal>:</para>
<programlisting><![CDATA[sess.createSQLQuery("SELECT * FROM CATS")
<programlisting role="JAVA"><![CDATA[sess.createSQLQuery("SELECT * FROM CATS")
.addScalar("ID", Hibernate.LONG)
.addScalar("NAME", Hibernate.STRING)
.addScalar("BIRTHDATE", Hibernate.DATE)
@ -93,7 +93,7 @@ sess.createSQLQuery("SELECT ID, NAME, BIRTHDATE FROM CATS").list();
<para>It is possible to leave out the type information for all or some
of the scalars.</para>
<programlisting><![CDATA[sess.createSQLQuery("SELECT * FROM CATS")
<programlisting role="JAVA"><![CDATA[sess.createSQLQuery("SELECT * FROM CATS")
.addScalar("ID", Hibernate.LONG)
.addScalar("NAME")
.addScalar("BIRTHDATE")
@ -118,7 +118,7 @@ sess.createSQLQuery("SELECT ID, NAME, BIRTHDATE FROM CATS").list();
shows how to get entity objects from a native sql query via
<literal>addEntity()</literal>.</para>
<programlisting><![CDATA[sess.createSQLQuery("SELECT * FROM CATS").addEntity(Cat.class);
<programlisting role="JAVA"><![CDATA[sess.createSQLQuery("SELECT * FROM CATS").addEntity(Cat.class);
sess.createSQLQuery("SELECT ID, NAME, BIRTHDATE FROM CATS").addEntity(Cat.class);
]]></programlisting>
@ -146,7 +146,7 @@ sess.createSQLQuery("SELECT ID, NAME, BIRTHDATE FROM CATS").addEntity(Cat.class)
example for a <literal>many-to-one</literal> to a
<literal>Dog</literal>:</para>
<programlisting><![CDATA[sess.createSQLQuery("SELECT ID, NAME, BIRTHDATE, DOG_ID FROM CATS").addEntity(Cat.class);
<programlisting role="JAVA"><![CDATA[sess.createSQLQuery("SELECT ID, NAME, BIRTHDATE, DOG_ID FROM CATS").addEntity(Cat.class);
]]></programlisting>
<para>This will allow cat.getDog() to function properly.</para>
@ -160,7 +160,7 @@ sess.createSQLQuery("SELECT ID, NAME, BIRTHDATE FROM CATS").addEntity(Cat.class)
done via the <literal>addJoin()</literal> method, which allows you to
join in an association or collection.</para>
<programlisting><![CDATA[sess.createSQLQuery("SELECT c.ID, NAME, BIRTHDATE, DOG_ID, D_ID, D_NAME FROM CATS c, DOGS d WHERE c.DOG_ID = d.D_ID")
<programlisting role="JAVA"><![CDATA[sess.createSQLQuery("SELECT c.ID, NAME, BIRTHDATE, DOG_ID, D_ID, D_NAME FROM CATS c, DOGS d WHERE c.DOG_ID = d.D_ID")
.addEntity("cat", Cat.class)
.addJoin("cat.dog");
]]></programlisting>
@ -173,7 +173,7 @@ sess.createSQLQuery("SELECT ID, NAME, BIRTHDATE FROM CATS").addEntity(Cat.class)
<literal>Cat</literal> had a one-to-many to <literal>Dog</literal>
instead.</para>
<programlisting><![CDATA[sess.createSQLQuery("SELECT ID, NAME, BIRTHDATE, D_ID, D_NAME, CAT_ID FROM CATS c, DOGS d WHERE c.ID = d.CAT_ID")
<programlisting role="JAVA"><![CDATA[sess.createSQLQuery("SELECT ID, NAME, BIRTHDATE, D_ID, D_NAME, CAT_ID FROM CATS c, DOGS d WHERE c.ID = d.CAT_ID")
.addEntity("cat", Cat.class)
.addJoin("cat.dogs");
]]></programlisting>
@ -196,7 +196,7 @@ sess.createSQLQuery("SELECT ID, NAME, BIRTHDATE FROM CATS").addEntity(Cat.class)
<para>Column alias injection is needed in the following query (which
most likely will fail):</para>
<programlisting><![CDATA[sess.createSQLQuery("SELECT c.*, m.* FROM CATS c, CATS m WHERE c.MOTHER_ID = c.ID")
<programlisting role="JAVA"><![CDATA[sess.createSQLQuery("SELECT c.*, m.* FROM CATS c, CATS m WHERE c.MOTHER_ID = c.ID")
.addEntity("cat", Cat.class)
.addEntity("mother", Cat.class)
]]></programlisting>
@ -215,7 +215,7 @@ sess.createSQLQuery("SELECT ID, NAME, BIRTHDATE FROM CATS").addEntity(Cat.class)
<para>The following form is not vulnerable to column name
duplication:</para>
<programlisting><![CDATA[sess.createSQLQuery("SELECT {cat.*}, {mother.*} FROM CATS c, CATS m WHERE c.MOTHER_ID = c.ID")
<programlisting role="JAVA"><![CDATA[sess.createSQLQuery("SELECT {cat.*}, {mother.*} FROM CATS c, CATS m WHERE c.MOTHER_ID = c.ID")
.addEntity("cat", Cat.class)
.addEntity("mother", Cat.class)
]]></programlisting>
@ -242,7 +242,7 @@ sess.createSQLQuery("SELECT ID, NAME, BIRTHDATE FROM CATS").addEntity(Cat.class)
declared in the mapping metadata. You can even use the
property aliases in the where clause.</para>
<programlisting><![CDATA[String sql = "SELECT ID as {c.id}, NAME as {c.name}, " +
<programlisting role="JAVA"><![CDATA[String sql = "SELECT ID as {c.id}, NAME as {c.name}, " +
"BIRTHDATE as {c.birthDate}, MOTHER_ID as {c.mother}, {mother.*} " +
"FROM CAT_LOG c, CAT_LOG m WHERE {c.mother} = c.ID";
@ -376,7 +376,7 @@ List loggedCats = sess.createSQLQuery(sql)
<para>It is possible to apply a ResultTransformer to native SQL queries, allowing it to return non-managed entities.</para>
<programlisting><![CDATA[sess.createSQLQuery("SELECT NAME, BIRTHDATE FROM CATS")
<programlisting role="JAVA"><![CDATA[sess.createSQLQuery("SELECT NAME, BIRTHDATE FROM CATS")
.setResultTransformer(Transformers.aliasToBean(CatDTO.class))]]></programlisting>
<para>This query specified:</para>
@ -411,7 +411,7 @@ List loggedCats = sess.createSQLQuery(sql)
<para>Native SQL queries support positional as well as named
parameters:</para>
<programlisting><![CDATA[Query query = sess.createSQLQuery("SELECT * FROM CATS WHERE NAME like ?").addEntity(Cat.class);
<programlisting role="JAVA"><![CDATA[Query query = sess.createSQLQuery("SELECT * FROM CATS WHERE NAME like ?").addEntity(Cat.class);
List pusList = query.setString(0, "Pus%").list();
query = sess.createSQLQuery("SELECT * FROM CATS WHERE NAME like :name").addEntity(Cat.class);
@ -430,7 +430,7 @@ List pusList = query.setString("name", "Pus%").list(); ]]></programlist
<emphasis>not</emphasis> need to call
<literal>addEntity()</literal>.</para>
<programlisting><![CDATA[<sql-query name="persons">
<programlisting role="XML"><![CDATA[<sql-query name="persons">
<return alias="person" class="eg.Person"/>
SELECT person.NAME AS {person.name},
person.AGE AS {person.age},
@ -439,7 +439,7 @@ List pusList = query.setString("name", "Pus%").list(); ]]></programlist
WHERE person.NAME LIKE :namePattern
</sql-query>]]></programlisting>
<programlisting><![CDATA[List people = sess.getNamedQuery("persons")
<programlisting role="JAVA"><![CDATA[List people = sess.getNamedQuery("persons")
.setString("namePattern", namePattern)
.setMaxResults(50)
.list();]]></programlisting>
@ -448,7 +448,7 @@ List pusList = query.setString("name", "Pus%").list(); ]]></programlist
the <literal>&lt;load-collection&gt;</literal> element is used to define queries which initialize collections,
</para>
<programlisting><![CDATA[<sql-query name="personsWith">
<programlisting role="XML"><![CDATA[<sql-query name="personsWith">
<return alias="person" class="eg.Person"/>
<return-join alias="address" property="person.mailingAddress"/>
SELECT person.NAME AS {person.name},
@ -468,7 +468,7 @@ List pusList = query.setString("name", "Pus%").list(); ]]></programlist
column alias and Hibernate type using the
<literal>&lt;return-scalar&gt;</literal> element:</para>
<programlisting><![CDATA[<sql-query name="mySqlQuery">
<programlisting role="XML"><![CDATA[<sql-query name="mySqlQuery">
<return-scalar column="name" type="string"/>
<return-scalar column="age" type="long"/>
SELECT p.NAME AS name,
@ -481,7 +481,7 @@ List pusList = query.setString("name", "Pus%").list(); ]]></programlist
several named queries or through the
<literal>setResultSetMapping()</literal> API.</para>
<programlisting><![CDATA[<resultset name="personAddress">
<programlisting role="XML"><![CDATA[<resultset name="personAddress">
<return alias="person" class="eg.Person"/>
<return-join alias="address" property="person.mailingAddress"/>
</resultset>
@ -503,7 +503,7 @@ List pusList = query.setString("name", "Pus%").list(); ]]></programlist
<para>You can, alternatively, use the resultset mapping information in your
hbm files directly in java code.</para>
<programlisting><![CDATA[List cats = sess.createSQLQuery(
<programlisting role="JAVA"><![CDATA[List cats = sess.createSQLQuery(
"select {cat.*}, {kitten.*} from cats cat, cats kitten where kitten.mother = cat.id"
)
.setResultSetMapping("catAndKitten")
@ -518,7 +518,7 @@ List pusList = query.setString("name", "Pus%").list(); ]]></programlist
<literal>{}</literal>-syntax to let Hibernate inject its own
aliases.For example:</para>
<programlisting><![CDATA[<sql-query name="mySqlQuery">
<programlisting role="XML"><![CDATA[<sql-query name="mySqlQuery">
<return alias="person" class="eg.Person">
<return-property name="name" column="myName"/>
<return-property name="age" column="myAge"/>
@ -536,7 +536,7 @@ List pusList = query.setString("name", "Pus%").list(); ]]></programlist
<literal>{}</literal>-syntax which cannot allow fine grained control of
multi-column properties.</para>
<programlisting><![CDATA[<sql-query name="organizationCurrentEmployments">
<programlisting role="XML"><![CDATA[<sql-query name="organizationCurrentEmployments">
<return alias="emp" class="Employment">
<return-property name="salary">
<return-column name="VALUE"/>
@ -571,7 +571,7 @@ List pusList = query.setString("name", "Pus%").list(); ]]></programlist
out-parameter to be able to work with Hibernate. An example of such a
stored function in Oracle 9 and higher is as follows:</para>
<programlisting><![CDATA[CREATE OR REPLACE FUNCTION selectAllEmployments
<programlisting role="XML"><![CDATA[CREATE OR REPLACE FUNCTION selectAllEmployments
RETURN SYS_REFCURSOR
AS
st_cursor SYS_REFCURSOR;
@ -587,7 +587,7 @@ BEGIN
<para>To use this query in Hibernate you need to map it via a named
query.</para>
<programlisting><![CDATA[<sql-query name="selectAllEmployees_SP" callable="true">
<programlisting role="XML"><![CDATA[<sql-query name="selectAllEmployees_SP" callable="true">
<return alias="emp" class="Employment">
<return-property name="employee" column="EMPLOYEE"/>
<return-property name="employer" column="EMPLOYER"/>
@ -675,7 +675,7 @@ BEGIN
<literal>&lt;sql-delete&gt;</literal>, and
<literal>&lt;sql-update&gt;</literal> override these strings:</para>
<programlisting><![CDATA[<class name="Person">
<programlisting role="XML"><![CDATA[<class name="Person">
<id name="id">
<generator class="increment"/>
</id>
@ -692,7 +692,7 @@ BEGIN
<para>Stored procedures are supported if the <literal>callable</literal>
attribute is set:</para>
<programlisting><![CDATA[<class name="Person">
<programlisting role="XML"><![CDATA[<class name="Person">
<id name="id">
<generator class="increment"/>
</id>
@ -743,7 +743,7 @@ END updatePerson;]]></programlisting>
or at the statement level. Here is an example of a statement level override:
</para>
<programlisting><![CDATA[<sql-query name="person">
<programlisting role="XML"><![CDATA[<sql-query name="person">
<return alias="pers" class="Person" lock-mode="upgrade"/>
SELECT NAME AS {pers.name}, ID AS {pers.id}
FROM PERSON
@ -754,7 +754,7 @@ END updatePerson;]]></programlisting>
<para>This is just a named query declaration, as discussed earlier. You
can reference this named query in a class mapping:</para>
<programlisting><![CDATA[<class name="Person">
<programlisting role="XML"><![CDATA[<class name="Person">
<id name="id">
<generator class="increment"/>
</id>
@ -766,13 +766,13 @@ END updatePerson;]]></programlisting>
<para>You can even define a query for collection loading:</para>
<programlisting><![CDATA[<set name="employments" inverse="true">
<programlisting role="XML"><![CDATA[<set name="employments" inverse="true">
<key/>
<one-to-many class="Employment"/>
<loader query-ref="employments"/>
</set>]]></programlisting>
<programlisting><![CDATA[<sql-query name="employments">
<programlisting role="XML"><![CDATA[<sql-query name="employments">
<load-collection alias="emp" role="Person.employments"/>
SELECT {emp.*}
FROM EMPLOYMENT emp
@ -783,7 +783,7 @@ END updatePerson;]]></programlisting>
<para>You can also define an entity loader that loads a collection by
join fetching:</para>
<programlisting><![CDATA[<sql-query name="person">
<programlisting role="XML"><![CDATA[<sql-query name="person">
<return alias="pers" class="Person"/>
<return-join alias="emp" property="pers.employments"/>
SELECT NAME AS {pers.*}, {emp.*}

View File

@ -107,7 +107,7 @@
session:
</para>
<programlisting><![CDATA[DomesticCat fritz = new DomesticCat();
<programlisting role="JAVA"><![CDATA[DomesticCat fritz = new DomesticCat();
fritz.setColor(Color.GINGER);
fritz.setSex('M');
fritz.setName("Fritz");
@ -151,7 +151,7 @@ Long generatedId = (Long) sess.save(fritz);]]></programlisting>
of <literal>save()</literal>.
</para>
<programlisting><![CDATA[DomesticCat pk = new DomesticCat();
<programlisting role="JAVA"><![CDATA[DomesticCat pk = new DomesticCat();
pk.setColor(Color.TABBY);
pk.setSex('F');
pk.setName("PK");
@ -189,9 +189,9 @@ sess.save( pk, new Long(1234) );]]></programlisting>
a newly instantiated instance of that class in a persistent state.
</para>
<programlisting><![CDATA[Cat fritz = (Cat) sess.load(Cat.class, generatedId);]]></programlisting>
<programlisting role="JAVA"><![CDATA[Cat fritz = (Cat) sess.load(Cat.class, generatedId);]]></programlisting>
<programlisting><![CDATA[// you need to wrap primitive identifiers
<programlisting role="JAVA"><![CDATA[// you need to wrap primitive identifiers
long id = 1234;
DomesticCat pk = (DomesticCat) sess.load( DomesticCat.class, new Long(id) );]]></programlisting>
@ -199,7 +199,7 @@ DomesticCat pk = (DomesticCat) sess.load( DomesticCat.class, new Long(id) );]]><
Alternatively, you can load state into a given instance:
</para>
<programlisting><![CDATA[Cat cat = new DomesticCat();
<programlisting role="JAVA"><![CDATA[Cat cat = new DomesticCat();
// load pk's state into cat
sess.load( cat, new Long(pkId) );
Set kittens = cat.getKittens();]]></programlisting>
@ -221,7 +221,7 @@ Set kittens = cat.getKittens();]]></programlisting>
returns null if there is no matching row.
</para>
<programlisting><![CDATA[Cat cat = (Cat) sess.get(Cat.class, id);
<programlisting role="JAVA"><![CDATA[Cat cat = (Cat) sess.get(Cat.class, id);
if (cat==null) {
cat = new Cat();
sess.save(cat, id);
@ -233,7 +233,7 @@ return cat;]]></programlisting>
using a <literal>LockMode</literal>. See the API documentation for more information.
</para>
<programlisting><![CDATA[Cat cat = (Cat) sess.get(Cat.class, id, LockMode.UPGRADE);]]></programlisting>
<programlisting role="JAVA"><![CDATA[Cat cat = (Cat) sess.get(Cat.class, id, LockMode.UPGRADE);]]></programlisting>
<para>
Any associated instances or contained collections will
@ -248,7 +248,7 @@ return cat;]]></programlisting>
initialize some of the properties of the object.
</para>
<programlisting><![CDATA[sess.save(cat);
<programlisting role="JAVA"><![CDATA[sess.save(cat);
sess.flush(); //force the SQL INSERT
sess.refresh(cat); //re-read the state (after the trigger executes)]]></programlisting>
@ -283,7 +283,7 @@ sess.refresh(cat); //re-read the state (after the trigger executes)]]></programl
<literal>Session</literal>:
</para>
<programlisting><![CDATA[List cats = session.createQuery(
<programlisting role="JAVA"><![CDATA[List cats = session.createQuery(
"from Cat as cat where cat.birthdate < ?")
.setDate(0, date)
.list();
@ -333,7 +333,7 @@ Set uniqueMothers = new HashSet(mothersWithKittens.list());]]></programlisting>
and <emphasis>n</emphasis> additional selects to initialize the actual instances.
</para>
<programlisting><![CDATA[// fetch ids
<programlisting role="JAVA"><![CDATA[// fetch ids
Iterator iter = sess.createQuery("from eg.Qux q order by q.likeliness").iterate();
while ( iter.hasNext() ) {
Qux qux = (Qux) iter.next(); // fetch the object
@ -355,7 +355,7 @@ while ( iter.hasNext() ) {
is returned as an array:
</para>
<programlisting><![CDATA[Iterator kittensAndMothers = sess.createQuery(
<programlisting role="JAVA"><![CDATA[Iterator kittensAndMothers = sess.createQuery(
"select kitten, mother from Cat kitten join kitten.mother mother")
.list()
.iterator();
@ -378,7 +378,7 @@ while ( kittensAndMothers.hasNext() ) {
"scalar" results and not entities in persistent state.
</para>
<programlisting><![CDATA[Iterator results = sess.createQuery(
<programlisting role="JAVA"><![CDATA[Iterator results = sess.createQuery(
"select cat.color, min(cat.birthdate), count(cat) from Cat cat " +
"group by cat.color")
.list()
@ -424,17 +424,17 @@ while ( results.hasNext() ) {
</listitem>
</itemizedlist>
<programlisting><![CDATA[//named parameter (preferred)
<programlisting role="JAVA"><![CDATA[//named parameter (preferred)
Query q = sess.createQuery("from DomesticCat cat where cat.name = :name");
q.setString("name", "Fritz");
Iterator cats = q.iterate();]]></programlisting>
<programlisting><![CDATA[//positional parameter
<programlisting role="JAVA"><![CDATA[//positional parameter
Query q = sess.createQuery("from DomesticCat cat where cat.name = ?");
q.setString(0, "Izi");
Iterator cats = q.iterate();]]></programlisting>
<programlisting><![CDATA[//named parameter list
<programlisting role="JAVA"><![CDATA[//named parameter list
List names = new ArrayList();
names.add("Izi");
names.add("Fritz");
@ -453,7 +453,7 @@ List cats = q.list();]]></programlisting>
use methods of the <literal>Query</literal> interface:
</para>
<programlisting><![CDATA[Query q = sess.createQuery("from DomesticCat cat");
<programlisting role="JAVA"><![CDATA[Query q = sess.createQuery("from DomesticCat cat");
q.setFirstResult(20);
q.setMaxResults(10);
List cats = q.list();]]></programlisting>
@ -475,7 +475,7 @@ List cats = q.list();]]></programlisting>
navigation of the query results.
</para>
<programlisting><![CDATA[Query q = sess.createQuery("select cat.name, cat from DomesticCat cat " +
<programlisting role="JAVA"><![CDATA[Query q = sess.createQuery("select cat.name, cat from DomesticCat cat " +
"order by cat.name");
ScrollableResults cats = q.scroll();
if ( cats.first() ) {
@ -514,7 +514,7 @@ cats.close()]]></programlisting>
be interpreted as markup.
</para>
<programlisting><![CDATA[<query name="ByNameAndMaximumWeight"><![CDATA[
<programlisting role="XML"><![CDATA[<query name="ByNameAndMaximumWeight"><![CDATA[
from eg.DomesticCat as cat
where cat.name = ?
and cat.weight > ?
@ -524,7 +524,7 @@ cats.close()]]></programlisting>
Parameter binding and executing is done programatically:
</para>
<programlisting><![CDATA[Query q = sess.getNamedQuery("ByNameAndMaximumWeight");
<programlisting role="JAVA"><![CDATA[Query q = sess.getNamedQuery("ByNameAndMaximumWeight");
q.setString(0, name);
q.setInt(1, minWeight);
List cats = q.list();]]></programlisting>
@ -555,7 +555,7 @@ List cats = q.list();]]></programlisting>
meaning the current collection element.
</para>
<programlisting><![CDATA[Collection blackKittens = session.createFilter(
<programlisting role="JAVA"><![CDATA[Collection blackKittens = session.createFilter(
pk.getKittens(),
"where this.color = ?")
.setParameter( Color.BLACK, Hibernate.custom(ColorUserType.class) )
@ -573,7 +573,7 @@ List cats = q.list();]]></programlisting>
one if required. Filters are not limited to returning the collection elements themselves.
</para>
<programlisting><![CDATA[Collection blackKittenMates = session.createFilter(
<programlisting role="JAVA"><![CDATA[Collection blackKittenMates = session.createFilter(
pk.getKittens(),
"select this.mate where this.color = eg.Color.BLACK.intValue")
.list();]]></programlisting>
@ -583,7 +583,7 @@ List cats = q.list();]]></programlisting>
large collection:
</para>
<programlisting><![CDATA[Collection tenKittens = session.createFilter(
<programlisting role="JAVA"><![CDATA[Collection tenKittens = session.createFilter(
mother.getKittens(), "")
.setFirstResult(0).setMaxResults(10)
.list();]]></programlisting>
@ -599,7 +599,7 @@ List cats = q.list();]]></programlisting>
an intuitive <literal>Criteria</literal> query API for these cases:
</para>
<programlisting><![CDATA[Criteria crit = session.createCriteria(Cat.class);
<programlisting role="JAVA"><![CDATA[Criteria crit = session.createCriteria(Cat.class);
crit.add( Restrictions.eq( "color", eg.Color.BLACK ) );
crit.setMaxResults(10);
List cats = crit.list();]]></programlisting>
@ -622,11 +622,11 @@ List cats = crit.list();]]></programlisting>
Hibernate API, you must enclose SQL aliases in braces:
</para>
<programlisting><![CDATA[List cats = session.createSQLQuery("SELECT {cat.*} FROM CAT {cat} WHERE ROWNUM<10")
<programlisting role="JAVA"><![CDATA[List cats = session.createSQLQuery("SELECT {cat.*} FROM CAT {cat} WHERE ROWNUM<10")
.addEntity("cat", Cat.class)
.list();]]></programlisting>
<programlisting><![CDATA[List cats = session.createSQLQuery(
<programlisting role="JAVA"><![CDATA[List cats = session.createSQLQuery(
"SELECT {cat}.ID AS {cat.id}, {cat}.SEX AS {cat.sex}, " +
"{cat}.MATE AS {cat.mate}, {cat}.SUBCLASS AS {cat.class}, ... " +
"FROM CAT {cat} WHERE ROWNUM<10")
@ -657,7 +657,7 @@ List cats = crit.list();]]></programlisting>
and then manipulate it directly while the <literal>Session</literal> is open:
</para>
<programlisting><![CDATA[DomesticCat cat = (DomesticCat) sess.load( Cat.class, new Long(69) );
<programlisting role="JAVA"><![CDATA[DomesticCat cat = (DomesticCat) sess.load( Cat.class, new Long(69) );
cat.setName("PK");
sess.flush(); // changes to cat are automatically detected and persisted]]></programlisting>
@ -700,7 +700,7 @@ sess.flush(); // changes to cat are automatically detected and persisted]]></pr
methods:
</para>
<programlisting><![CDATA[// in the first session
<programlisting role="JAVA"><![CDATA[// in the first session
Cat cat = (Cat) firstSession.load(Cat.class, catId);
Cat potentialMate = new Cat();
firstSession.save(potentialMate);
@ -739,7 +739,7 @@ secondSession.update(mate); // update mate]]></programlisting>
an object with a new session. However, the detached instance has to be unmodified.
</para>
<programlisting><![CDATA[//just reassociate:
<programlisting role="JAVA"><![CDATA[//just reassociate:
sess.lock(fritz, LockMode.NONE);
//do a version check, then reassociate:
sess.lock(izi, LockMode.READ);
@ -769,7 +769,7 @@ sess.lock(pk, LockMode.UPGRADE);]]></programlisting>
The <literal>saveOrUpdate()</literal> method implements this functionality.
</para>
<programlisting><![CDATA[// in the first session
<programlisting role="JAVA"><![CDATA[// in the first session
Cat cat = (Cat) firstSession.load(Cat.class, catID);
// in a higher tier of the application
@ -907,7 +907,7 @@ secondSession.saveOrUpdate(mate); // save the new instance (mate has a null id)
transient.
</para>
<programlisting><![CDATA[sess.delete(cat);]]></programlisting>
<programlisting role="JAVA"><![CDATA[sess.delete(cat);]]></programlisting>
<para>
You can delete objects in any order, without risk of foreign key
@ -928,7 +928,7 @@ secondSession.saveOrUpdate(mate); // save the new instance (mate has a null id)
values.
</para>
<programlisting><![CDATA[//retrieve a cat from one database
<programlisting role="JAVA"><![CDATA[//retrieve a cat from one database
Session session1 = factory1.openSession();
Transaction tx1 = session1.beginTransaction();
Cat cat = session1.get(Cat.class, catId);
@ -1073,7 +1073,7 @@ session2.close();]]></programlisting>
a long time (see <xref linkend="transactions-optimistic-longsession"/>).
</para>
<programlisting><![CDATA[sess = sf.openSession();
<programlisting role="JAVA"><![CDATA[sess = sf.openSession();
Transaction tx = sess.beginTransaction();
sess.setFlushMode(FlushMode.COMMIT); // allow queries to return stale state
@ -1134,13 +1134,13 @@ sess.close();]]></programlisting>
document. For example:
</para>
<programlisting><![CDATA[<one-to-one name="person" cascade="persist"/>]]></programlisting>
<programlisting role="XML"><![CDATA[<one-to-one name="person" cascade="persist"/>]]></programlisting>
<para>
Cascade styles my be combined:
</para>
<programlisting><![CDATA[<one-to-one name="person" cascade="persist,delete,lock"/>]]></programlisting>
<programlisting role="XML"><![CDATA[<one-to-one name="person" cascade="persist,delete,lock"/>]]></programlisting>
<para>
You can even use <literal>cascade="all"</literal> to specify that <emphasis>all</emphasis>
@ -1267,7 +1267,7 @@ sess.close();]]></programlisting>
<literal>SessionFactory</literal>.
</para>
<programlisting><![CDATA[Cat fritz = ......;
<programlisting role="JAVA"><![CDATA[Cat fritz = ......;
ClassMetadata catMeta = sessionfactory.getClassMetadata(Cat.class);
Object[] propertyValues = catMeta.getPropertyValues(fritz);

View File

@ -105,8 +105,8 @@
</para>
<programlisting><![CDATA[<property name="zip" length="5"/>]]></programlisting>
<programlisting><![CDATA[<property name="balance" precision="12" scale="2"/>]]></programlisting>
<programlisting role="XML"><![CDATA[<property name="zip" length="5"/>]]></programlisting>
<programlisting role="XML"><![CDATA[<property name="balance" precision="12" scale="2"/>]]></programlisting>
<para>
Some tags also accept a <literal>not-null</literal> attribute for generating a
@ -114,9 +114,9 @@
attribute for generating <literal>UNIQUE</literal> constraint on table columns.
</para>
<programlisting><![CDATA[<many-to-one name="bar" column="barId" not-null="true"/>]]></programlisting>
<programlisting role="XML"><![CDATA[<many-to-one name="bar" column="barId" not-null="true"/>]]></programlisting>
<programlisting><![CDATA[<element column="serialNumber" type="long" not-null="true" unique="true"/>]]></programlisting>
<programlisting role="XML"><![CDATA[<element column="serialNumber" type="long" not-null="true" unique="true"/>]]></programlisting>
<para>
A <literal>unique-key</literal> attribute can be used to group columns in
@ -126,7 +126,7 @@
the mapping file.
</para>
<programlisting><![CDATA[<many-to-one name="org" column="orgId" unique-key="OrgEmployeeId"/>
<programlisting role="XML"><![CDATA[<many-to-one name="org" column="orgId" unique-key="OrgEmployeeId"/>
<property name="employeeId" unique-key="OrgEmployee"/>]]></programlisting>
<para>
@ -135,7 +135,7 @@
grouped into the same index by simply specifying the same index name.
</para>
<programlisting><![CDATA[<property name="lastName" index="CustName"/>
<programlisting role="XML"><![CDATA[<property name="lastName" index="CustName"/>
<property name="firstName" index="CustName"/>]]></programlisting>
<para>
@ -143,14 +143,14 @@
of any generated foreign key constraint.
</para>
<programlisting><![CDATA[<many-to-one name="bar" column="barId" foreign-key="FKFooBar"/>]]></programlisting>
<programlisting role="XML"><![CDATA[<many-to-one name="bar" column="barId" foreign-key="FKFooBar"/>]]></programlisting>
<para>
Many mapping elements also accept a child <literal>&lt;column&gt;</literal> element.
This is particularly useful for mapping multi-column types:
</para>
<programlisting><![CDATA[<property name="name" type="my.customtypes.Name"/>
<programlisting role="XML"><![CDATA[<property name="name" type="my.customtypes.Name"/>
<column name="last" not-null="true" index="bar_idx" length="30"/>
<column name="first" not-null="true" index="bar_idx" length="20"/>
<column name="initial"/>
@ -162,11 +162,11 @@
saving a new instance of the mapped class.
</para>
<programlisting><![CDATA[<property name="credits" type="integer" insert="false">
<programlisting role="XML"><![CDATA[<property name="credits" type="integer" insert="false">
<column name="credits" default="10"/>
</property>]]></programlisting>
<programlisting><![CDATA[<version name="version" type="integer" insert="false">
<programlisting role="XML"><![CDATA[<version name="version" type="integer" insert="false">
<column name="version" default="0"/>
</property>]]></programlisting>
@ -175,7 +175,7 @@
mapping of a Hibernate type to SQL datatype.
</para>
<programlisting><![CDATA[<property name="balance" type="float">
<programlisting role="XML"><![CDATA[<property name="balance" type="float">
<column name="balance" sql-type="decimal(13,3)"/>
</property>]]></programlisting>
@ -183,11 +183,11 @@
The <literal>check</literal> attribute allows you to specify a check constraint.
</para>
<programlisting><![CDATA[<property name="foo" type="integer">
<programlisting role="XML"><![CDATA[<property name="foo" type="integer">
<column name="foo" check="foo > 10"/>
</property>]]></programlisting>
<programlisting><![CDATA[<class name="Foo" table="foos" check="bar < 100.0">
<programlisting role="XML"><![CDATA[<class name="Foo" table="foos" check="bar < 100.0">
...
<property name="bar" type="float"/>
</class>]]></programlisting>
@ -287,12 +287,12 @@
for the generated schema.
</para>
<programlisting><![CDATA[<class name="Customer" table="CurCust">
<programlisting role="XML"><![CDATA[<class name="Customer" table="CurCust">
<comment>Current customers only</comment>
...
</class>]]></programlisting>
<programlisting><![CDATA[<property name="balance">
<programlisting role="XML"><![CDATA[<property name="balance">
<column name="bal">
<comment>Balance in USD</comment>
</column>
@ -381,7 +381,7 @@
You can even embed <literal>SchemaExport</literal> in your application:
</para>
<programlisting><![CDATA[Configuration cfg = ....;
<programlisting role="JAVA"><![CDATA[Configuration cfg = ....;
new SchemaExport(cfg).create(false, true);]]></programlisting>
</sect2>
@ -454,7 +454,7 @@ new SchemaExport(cfg).create(false, true);]]></programlisting>
You can call <literal>SchemaExport</literal> from your Ant build script:
</para>
<programlisting><![CDATA[<target name="schemaexport">
<programlisting role="XML"><![CDATA[<target name="schemaexport">
<taskdef name="schemaexport"
classname="org.hibernate.tool.hbm2ddl.SchemaExportTask"
classpathref="class.path"/>
@ -528,7 +528,7 @@ new SchemaExport(cfg).create(false, true);]]></programlisting>
You can embed <literal>SchemaUpdate</literal> in your application:
</para>
<programlisting><![CDATA[Configuration cfg = ....;
<programlisting role="JAVA"><![CDATA[Configuration cfg = ....;
new SchemaUpdate(cfg).execute(false);]]></programlisting>
</sect2>
@ -540,7 +540,7 @@ new SchemaUpdate(cfg).execute(false);]]></programlisting>
You can call <literal>SchemaUpdate</literal> from the Ant script:
</para>
<programlisting><![CDATA[<target name="schemaupdate">
<programlisting role="XML"><![CDATA[<target name="schemaupdate">
<taskdef name="schemaupdate"
classname="org.hibernate.tool.hbm2ddl.SchemaUpdateTask"
classpathref="class.path"/>
@ -603,7 +603,7 @@ new SchemaUpdate(cfg).execute(false);]]></programlisting>
You can embed <literal>SchemaValidator</literal> in your application:
</para>
<programlisting><![CDATA[Configuration cfg = ....;
<programlisting role="JAVA"><![CDATA[Configuration cfg = ....;
new SchemaValidator(cfg).validate();]]></programlisting>
</sect2>
@ -615,7 +615,7 @@ new SchemaValidator(cfg).validate();]]></programlisting>
You can call <literal>SchemaValidator</literal> from the Ant script:
</para>
<programlisting><![CDATA[<target name="schemavalidate">
<programlisting role="XML"><![CDATA[<target name="schemavalidate">
<taskdef name="schemavalidator"
classname="org.hibernate.tool.hbm2ddl.SchemaValidatorTask"
classpathref="class.path"/>

View File

@ -457,7 +457,7 @@
like this:
</para>
<programlisting><![CDATA[// Non-managed environment idiom
<programlisting role="JAVA"><![CDATA[// Non-managed environment idiom
Session sess = factory.openSession();
Transaction tx = null;
try {
@ -490,7 +490,7 @@ finally {
management:
</para>
<programlisting><![CDATA[// Non-managed environment idiom with getCurrentSession()
<programlisting role="JAVA"><![CDATA[// Non-managed environment idiom with getCurrentSession()
try {
factory.getCurrentSession().beginTransaction();
@ -538,7 +538,7 @@ catch (RuntimeException e) {
transaction management code is identical to the non-managed environment.
</para>
<programlisting><![CDATA[// BMT idiom
<programlisting role="JAVA"><![CDATA[// BMT idiom
Session sess = factory.openSession();
Transaction tx = null;
try {
@ -563,7 +563,7 @@ finally {
use the JTA <literal>UserTransaction</literal> API directly:
</para>
<programlisting><![CDATA[// BMT idiom with getCurrentSession()
<programlisting role="JAVA"><![CDATA[// BMT idiom with getCurrentSession()
try {
UserTransaction tx = (UserTransaction)new InitialContext()
.lookup("java:comp/UserTransaction");
@ -586,7 +586,7 @@ catch (RuntimeException e) {
The code is reduced to:
</para>
<programlisting><![CDATA[// CMT idiom
<programlisting role="JAVA"><![CDATA[// CMT idiom
Session sess = factory.getCurrentSession();
// do some work
@ -716,7 +716,7 @@ catch (RuntimeException e) {
<literal>Transaction</literal> object.
</para>
<programlisting><![CDATA[
<programlisting role="JAVA"><![CDATA[
Session sess = factory.openSession();
try {
//set transaction timeout to 3 seconds
@ -770,7 +770,7 @@ finally {
database access. It is the approach most similar to entity EJBs.
</para>
<programlisting><![CDATA[// foo is an instance loaded by a previous Session
<programlisting role="JAVA"><![CDATA[// foo is an instance loaded by a previous Session
session = factory.openSession();
Transaction t = session.beginTransaction();
@ -827,7 +827,7 @@ session.close();]]></programlisting>
database transaction.
</para>
<programlisting><![CDATA[// foo is an instance loaded earlier by the old session
<programlisting role="JAVA"><![CDATA[// foo is an instance loaded earlier by the old session
Transaction t = session.beginTransaction(); // Obtain a new JDBC connection, start transaction
foo.setProperty("bar");
@ -896,7 +896,7 @@ session.close(); // Only for last transaction in conversation]]></programlist
<literal>Session.saveOrUpdate()</literal>, or <literal>Session.merge()</literal>.
</para>
<programlisting><![CDATA[// foo is an instance loaded by a previous Session
<programlisting role="JAVA"><![CDATA[// foo is an instance loaded by a previous Session
foo.setProperty("bar");
session = factory.openSession();
Transaction t = session.beginTransaction();

View File

@ -91,7 +91,7 @@
many IDEs to automatically set up a project for us based on the maven descriptor.
</para>
<programlisting><![CDATA[<project xmlns="http://maven.apache.org/POM/4.0.0"
<programlisting role="XML"><![CDATA[<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
@ -166,7 +166,7 @@
database; it is a simple JavaBean class with some properties:
</para>
<programlisting><![CDATA[package org.hibernate.tutorial.domain;
<programlisting role="JAVA"><![CDATA[package org.hibernate.tutorial.domain;
import java.util.Date;
@ -255,7 +255,7 @@ public class Event {
The basic structure of a mapping file looks like this:
</para>
<programlisting><![CDATA[<?xml version="1.0"?>
<programlisting role="XML"><![CDATA[<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
@ -290,7 +290,7 @@ public class Event {
a mapping to a table in the SQL database:
</para>
<programlisting><![CDATA[<hibernate-mapping package="org.hibernate.tutorial.domain">
<programlisting role="XML"><![CDATA[<hibernate-mapping package="org.hibernate.tutorial.domain">
<class name="Event" table="EVENTS">
@ -308,7 +308,7 @@ public class Event {
identifier generation strategy for a surrogate primary key column:
</para>
<programlisting><![CDATA[<hibernate-mapping package="org.hibernate.tutorial.domain">
<programlisting role="XML"><![CDATA[<hibernate-mapping package="org.hibernate.tutorial.domain">
<class name="Event" table="EVENTS">
<id name="id" column="EVENT_ID">
@ -352,7 +352,7 @@ public class Event {
persistent:
</para>
<programlisting><![CDATA[
<programlisting role="XML"><![CDATA[
<hibernate-mapping package="org.hibernate.tutorial.domain">
<class name="Event" table="EVENTS">
@ -465,7 +465,7 @@ public class Event {
programmatic setup. Most users prefer the XML configuration file:
</para>
<programlisting><![CDATA[<?xml version='1.0' encoding='utf-8'?>
<programlisting role="XML"><![CDATA[<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
@ -600,7 +600,7 @@ public class Event {
<interfacename>org.hibernate.SessionFactory</interfacename> more convenient.
</para>
<programlisting><![CDATA[package org.hibernate.tutorial.util;
<programlisting role="JAVA"><![CDATA[package org.hibernate.tutorial.util;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
@ -676,7 +676,7 @@ public class HibernateUtil {
with a <literal>main()</literal> method:
</para>
<programlisting><![CDATA[package org.hibernate.tutorial;
<programlisting role="JAVA"><![CDATA[package org.hibernate.tutorial;
import org.hibernate.Session;
@ -817,7 +817,7 @@ public class EventManager {
To list stored events an option is added to the main method:
</para>
<programlisting><![CDATA[ if (args[0].equals("store")) {
<programlisting role="JAVA"><![CDATA[ if (args[0].equals("store")) {
mgr.createAndStoreEvent("My Event", new Date());
}
else if (args[0].equals("list")) {
@ -834,7 +834,7 @@ public class EventManager {
A new <literal>listEvents() method is also added</literal>:
</para>
<programlisting><![CDATA[ private List listEvents() {
<programlisting role="JAVA"><![CDATA[ private List listEvents() {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
List result = session.createQuery("from Event").list();
@ -876,7 +876,7 @@ public class EventManager {
The first cut of the <literal>Person</literal> class looks like this:
</para>
<programlisting><![CDATA[package org.hibernate.tutorial.domain;
<programlisting role="JAVA"><![CDATA[package org.hibernate.tutorial.domain;
public class Person {
@ -901,7 +901,7 @@ public class Person {
<filename>src/main/resources/org/hibernate/tutorial/domain/Person.hbm.xml</filename>
</para>
<programlisting><![CDATA[<hibernate-mapping package="org.hibernate.tutorial.domain">
<programlisting role="XML"><![CDATA[<hibernate-mapping package="org.hibernate.tutorial.domain">
<class name="Person" table="PERSON">
<id name="id" column="PERSON_ID">
@ -918,7 +918,7 @@ public class Person {
Finally, add the new mapping to Hibernate's configuration:
</para>
<programlisting><![CDATA[<mapping resource="events/Event.hbm.xml"/>
<programlisting role="XML"><![CDATA[<mapping resource="events/Event.hbm.xml"/>
<mapping resource="events/Person.hbm.xml"/>]]></programlisting>
<para>
@ -944,7 +944,7 @@ public class Person {
is not relevant to our examples:
</para>
<programlisting><![CDATA[public class Person {
<programlisting role="JAVA"><![CDATA[public class Person {
private Set events = new HashSet();
@ -970,7 +970,7 @@ public class Person {
association. Hence, we use Hibernate's many-to-many mapping:
</para>
<programlisting><![CDATA[<class name="Person" table="PERSON">
<programlisting role="XML"><![CDATA[<class name="Person" table="PERSON">
<id name="id" column="PERSON_ID">
<generator class="native"/>
</id>
@ -1028,7 +1028,7 @@ public class Person {
Now we will bring some people and events together in a new method in <literal>EventManager</literal>:
</para>
<programlisting><![CDATA[ private void addPersonToEvent(Long personId, Long eventId) {
<programlisting role="JAVA"><![CDATA[ private void addPersonToEvent(Long personId, Long eventId) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
@ -1067,7 +1067,7 @@ public class Person {
modify a collection when it is detached:
</para>
<programlisting><![CDATA[ private void addPersonToEvent(Long personId, Long eventId) {
<programlisting role="JAVA"><![CDATA[ private void addPersonToEvent(Long personId, Long eventId) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
@ -1109,7 +1109,7 @@ public class Person {
returns it (you might have to modify some of the previous methods to return that identifier):
</para>
<programlisting><![CDATA[ else if (args[0].equals("addpersontoevent")) {
<programlisting role="JAVA"><![CDATA[ else if (args[0].equals("addpersontoevent")) {
Long eventId = mgr.createAndStoreEvent("My Event", new Date());
Long personId = mgr.createAndStorePerson("Foo", "Bar");
mgr.addPersonToEvent(personId, eventId);
@ -1151,7 +1151,7 @@ public class Person {
<interfacename>java.util.Set</interfacename> of
<classname>java.lang.String</classname> instances:
</para>
<programlisting><![CDATA[ private Set emailAddresses = new HashSet();
<programlisting role="JAVA"><![CDATA[ private Set emailAddresses = new HashSet();
public Set getEmailAddresses() {
return emailAddresses;
@ -1165,7 +1165,7 @@ public class Person {
The mapping of this <literal>Set</literal> is as follows:
</para>
<programlisting><![CDATA[ <set name="emailAddresses" table="PERSON_EMAIL_ADDR">
<programlisting role="XML"><![CDATA[ <set name="emailAddresses" table="PERSON_EMAIL_ADDR">
<key column="PERSON_ID"/>
<element type="string" column="EMAIL_ADDR"/>
</set>]]></programlisting>
@ -1215,7 +1215,7 @@ public class Person {
linking persons and events. It is the same code in Java:
</para>
<programlisting><![CDATA[ private void addEmailToPerson(Long personId, String emailAddress) {
<programlisting role="JAVA"><![CDATA[ private void addEmailToPerson(Long personId, String emailAddress) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
@ -1258,7 +1258,7 @@ public class Person {
<literal>Event</literal> class:
</para>
<programlisting><![CDATA[ private Set participants = new HashSet();
<programlisting role="JAVA"><![CDATA[ private Set participants = new HashSet();
public Set getParticipants() {
return participants;
@ -1272,7 +1272,7 @@ public class Person {
Now map this side of the association in <literal>Event.hbm.xml</literal>.
</para>
<programlisting><![CDATA[ <set name="participants" table="PERSON_EVENT" inverse="true">
<programlisting role="XML"><![CDATA[ <set name="participants" table="PERSON_EVENT" inverse="true">
<key column="EVENT_ID"/>
<many-to-many column="PERSON_ID" class="events.Person"/>
</set>]]></programlisting>
@ -1311,7 +1311,7 @@ public class Person {
correctly set both sides (for example, in <literal>Person</literal>):
</para>
<programlisting><![CDATA[ protected Set getEvents() {
<programlisting role="JAVA"><![CDATA[ protected Set getEvents() {
return events;
}
@ -1370,7 +1370,7 @@ public class Person {
will only implement the <literal>doGet()</literal> method:
</para>
<programlisting><![CDATA[package org.hibernate.tutorial.web;
<programlisting role="JAVA"><![CDATA[package org.hibernate.tutorial.web;
// Imports
@ -1450,7 +1450,7 @@ public class EventManagerServlet extends HttpServlet {
Now you can implement the processing of the request and the rendering of the page.
</para>
<programlisting><![CDATA[ // Write HTML header
<programlisting role="JAVA"><![CDATA[ // Write HTML header
PrintWriter out = response.getWriter();
out.println("<html><head><title>Event Manager</title></head><body>");
@ -1487,7 +1487,7 @@ public class EventManagerServlet extends HttpServlet {
trivial and only outputs HTML:
</para>
<programlisting><![CDATA[ private void printEventForm(PrintWriter out) {
<programlisting role="JAVA"><![CDATA[ private void printEventForm(PrintWriter out) {
out.println("<h2>Add new event:</h2>");
out.println("<form>");
out.println("Title: <input name='eventTitle' length='50'/><br/>");
@ -1502,7 +1502,7 @@ public class EventManagerServlet extends HttpServlet {
a query:
</para>
<programlisting><![CDATA[ private void listEvents(PrintWriter out, SimpleDateFormat dateFormatter) {
<programlisting role="JAVA"><![CDATA[ private void listEvents(PrintWriter out, SimpleDateFormat dateFormatter) {
List result = HibernateUtil.getSessionFactory()
.getCurrentSession().createCriteria(Event.class).list();
@ -1531,7 +1531,7 @@ public class EventManagerServlet extends HttpServlet {
the <literal>Session</literal> of the current thread:
</para>
<programlisting><![CDATA[ protected void createAndStoreEvent(String title, Date theDate) {
<programlisting role="JAVA"><![CDATA[ protected void createAndStoreEvent(String title, Date theDate) {
Event theEvent = new Event();
theEvent.setTitle(title);
theEvent.setDate(theDate);
@ -1562,7 +1562,7 @@ public class EventManagerServlet extends HttpServlet {
as <filename>src/main/webapp/WEB-INF/web.xml</filename>
</para>
<programlisting><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<programlisting role="XML"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

View File

@ -71,7 +71,7 @@
Here is an example of mapping a POJO and XML simultaneously:
</para>
<programlisting><![CDATA[<class name="Account"
<programlisting role="XML"><![CDATA[<class name="Account"
table="ACCOUNTS"
node="account">
@ -100,7 +100,7 @@
Here is an example where there is no POJO class:
</para>
<programlisting><![CDATA[<class entity-name="Account"
<programlisting role="XML"><![CDATA[<class entity-name="Account"
table="ACCOUNTS"
node="account">
@ -177,7 +177,7 @@
too many associations, since XML does not deal well with circularity.
</para>
<programlisting><![CDATA[<class name="Customer"
<programlisting role="XML"><![CDATA[<class name="Customer"
table="CUSTOMER"
node="customer">
@ -223,7 +223,7 @@
would return datasets such as this:
</para>
<programlisting><![CDATA[<customer id="123456789">
<programlisting role="XML"><![CDATA[<customer id="123456789">
<account short-desc="Savings">987632567</account>
<account short-desc="Credit Card">985612323</account>
<name>
@ -239,7 +239,7 @@
mapping, the data might look more like this:
</para>
<programlisting><![CDATA[<customer id="123456789">
<programlisting role="XML"><![CDATA[<customer id="123456789">
<account id="987632567" short-desc="Savings">
<customer id="123456789"/>
<balance>100.29</balance>
@ -267,7 +267,7 @@
obtaining a dom4j session:
</para>
<programlisting><![CDATA[Document doc = ....;
<programlisting role="JAVA"><![CDATA[Document doc = ....;
Session session = factory.openSession();
Session dom4jSession = session.getSession(EntityMode.DOM4J);
@ -285,7 +285,7 @@ for ( int i=0; i<results.size(); i++ ) {
tx.commit();
session.close();]]></programlisting>
<programlisting><![CDATA[Session session = factory.openSession();
<programlisting role="JAVA"><![CDATA[Session session = factory.openSession();
Session dom4jSession = session.getSession(EntityMode.DOM4J);
Transaction tx = session.beginTransaction();