HHH-4933 move to jHighlighting

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18940 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Emmanuel Bernard 2010-03-09 14:49:39 +00:00
parent 5bd9ffa511
commit 9be297241d
4 changed files with 143 additions and 136 deletions

View File

@ -122,7 +122,7 @@
<literal>ddl</literal> together by setting the property to <literal>ddl</literal> together by setting the property to
<literal>callback, dll</literal></para> <literal>callback, dll</literal></para>
<programlisting role="XML" language="XML">&lt;persistence ...&gt; <programlisting language="XML" role="XML">&lt;persistence ...&gt;
&lt;persistence-unit ...&gt; &lt;persistence-unit ...&gt;
... ...
&lt;properties&gt; &lt;properties&gt;
@ -171,7 +171,7 @@
<example> <example>
<title>Using custom groups for validation</title> <title>Using custom groups for validation</title>
<programlisting role="XML" language="XML">&lt;persistence ...&gt; <programlisting language="XML" role="XML">&lt;persistence ...&gt;
&lt;persistence-unit ...&gt; &lt;persistence-unit ...&gt;
... ...
&lt;properties&gt; &lt;properties&gt;

View File

@ -63,7 +63,7 @@
<para>Every persistent POJO class is an entity and is declared using the <para>Every persistent POJO class is an entity and is declared using the
<literal>@Entity</literal> annotation (at the class level):</para> <literal>@Entity</literal> annotation (at the class level):</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Flight implements Serializable { public class Flight implements Serializable {
Long id; Long id;
@ -102,7 +102,7 @@ public class Flight implements Serializable {
mapping. If no <literal>@Table</literal> is defined the default values mapping. If no <literal>@Table</literal> is defined the default values
are used: the unqualified class name of the entity.</para> are used: the unqualified class name of the entity.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
@Table(name="tbl_sky") @Table(name="tbl_sky")
public class Sky implements Serializable { public class Sky implements Serializable {
... ...
@ -117,7 +117,7 @@ public class Sky implements Serializable {
<code>@Column.unique</code> approach (refer to <code>@Column.unique</code> approach (refer to
<literal>@Column</literal> for more information).</para> <literal>@Column</literal> for more information).</para>
<programlisting role="JAVA" language="JAVA">@Table(name="tbl_sky", <programlisting language="JAVA" role="JAVA">@Table(name="tbl_sky",
uniqueConstraints = {@UniqueConstraint(columnNames={"month", "day"})} uniqueConstraints = {@UniqueConstraint(columnNames={"month", "day"})}
)</programlisting> )</programlisting>
@ -142,7 +142,7 @@ public class Sky implements Serializable {
<para>You can add optimistic locking capability to an entity using the <para>You can add optimistic locking capability to an entity using the
<literal>@Version</literal> annotation:</para> <literal>@Version</literal> annotation:</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Flight implements Serializable { public class Flight implements Serializable {
... ...
@Version @Version
@ -182,7 +182,7 @@ public class Flight implements Serializable {
annotation allows you to declare the fetching strategy for a annotation allows you to declare the fetching strategy for a
property:</para> property:</para>
<programlisting role="JAVA" language="JAVA">public transient int counter; //transient property <programlisting language="JAVA" role="JAVA">public transient int counter; //transient property
private String firstname; //persistent property private String firstname; //persistent property
@ -252,7 +252,7 @@ Starred getNote() { ... } //enum persisted as String in database</programlisting
<classname>byte[] </classname>and serializable type will be persisted <classname>byte[] </classname>and serializable type will be persisted
in a Blob.</para> in a Blob.</para>
<programlisting role="JAVA" language="JAVA"> <programlisting language="JAVA" role="JAVA">
@Lob @Lob
public String getFullText() { public String getFullText() {
return fullText; return fullText;
@ -313,7 +313,7 @@ public byte[] getFullCode() {
<para>To force the access type on a given class, use the <para>To force the access type on a given class, use the
<classname>@Access</classname> annotation as showed below:</para> <classname>@Access</classname> annotation as showed below:</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Order { public class Order {
@Id private Long id; @Id private Long id;
public Long getId() { return id; } public Long getId() { return id; }
@ -348,7 +348,7 @@ public class Address {
<para>You can also override the access type of a single property while <para>You can also override the access type of a single property while
keeping the other properties standard.</para> keeping the other properties standard.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Order { public class Order {
@Id private Long id; @Id private Long id;
public Long getId() { return id; } public Long getId() { return id; }
@ -408,7 +408,7 @@ public class Order {
</listitem> </listitem>
</itemizedlist> </itemizedlist>
<programlisting role="JAVA" language="JAVA"> <programlisting language="JAVA" role="JAVA">
@Entity @Entity
public class Flight implements Serializable { public class Flight implements Serializable {
... ...
@ -448,7 +448,7 @@ public String getName() { ... }
<area coords="11 55" id="hm10" /> <area coords="11 55" id="hm10" />
</areaspec> </areaspec>
<programlisting role="JAVA" language="JAVA">@Column( <programlisting language="JAVA" role="JAVA">@Column(
name="columnName"; name="columnName";
boolean unique() default false; boolean unique() default false;
boolean nullable() default true; boolean nullable() default true;
@ -528,7 +528,7 @@ public String getName() { ... }
<literal>@Embedded</literal> and <literal>@AttributeOverride</literal> <literal>@Embedded</literal> and <literal>@AttributeOverride</literal>
annotation in the associated property:</para> annotation in the associated property:</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Person implements Serializable { public class Person implements Serializable {
// Persistent component using defaults // Persistent component using defaults
@ -543,13 +543,13 @@ public class Person implements Serializable {
... ...
} </programlisting> } </programlisting>
<programlisting role="JAVA" language="JAVA">@Embeddable <programlisting language="JAVA" role="JAVA">@Embeddable
public class Address implements Serializable { public class Address implements Serializable {
String city; String city;
Country nationality; //no overriding here Country nationality; //no overriding here
} </programlisting> } </programlisting>
<programlisting role="JAVA" language="JAVA">@Embeddable <programlisting language="JAVA" role="JAVA">@Embeddable
public class Country implements Serializable { public class Country implements Serializable {
private String iso2; private String iso2;
@Column(name="countryName") private String name; @Column(name="countryName") private String name;
@ -582,19 +582,20 @@ public class Country implements Serializable {
columns of embedded objects of embedded objects is through dotted columns of embedded objects of embedded objects is through dotted
expressions.</para> expressions.</para>
<programlisting role="JAVA" language="JAVA"> @Embedded <programlisting language="JAVA" role="JAVA"> @Embedded
@AttributeOverrides( { @AttributeOverrides( {
@AttributeOverride(name="city", column = @Column(name="fld_city") ), @AttributeOverride(name="city", column = @Column(name="fld_city") ),
@AttributeOverride(name="nationality.iso2", column = @Column(name="nat_Iso2") ), @AttributeOverride(name="nationality.iso2", column = @Column(name="nat_Iso2") ),
@AttributeOverride(name="nationality.name", column = @Column(name="nat_CountryName") ) @AttributeOverride(name="nationality.name", column = @Column(name="nat_CountryName") )
//nationality columns in homeAddress are overridden //nationality columns in homeAddress are overridden
} ) } )
Address homeAddress;</programlisting><para>Hibernate Annotations supports Address homeAddress;</programlisting>
something that is not explicitly supported by the JPA specification.
You can annotate a embedded object with the <para>Hibernate Annotations supports something that is not explicitly
<literal>@MappedSuperclass</literal> annotation to make the superclass supported by the JPA specification. You can annotate a embedded object
properties persistent (see <literal>@MappedSuperclass</literal> for with the <literal>@MappedSuperclass</literal> annotation to make the
more informations).</para> superclass properties persistent (see
<literal>@MappedSuperclass</literal> for more informations).</para>
<para>You can also use association annotations in an embeddable object <para>You can also use association annotations in an embeddable object
(ie <literal>@OneToOne</literal>, <classname>@ManyToOne</classname>, (ie <literal>@OneToOne</literal>, <classname>@ManyToOne</classname>,
@ -691,12 +692,12 @@ public class Country implements Serializable {
<para>The following example shows a sequence generator using the <para>The following example shows a sequence generator using the
SEQ_STORE configuration (see below)</para> SEQ_STORE configuration (see below)</para>
<programlisting role="JAVA" language="JAVA">@Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_STORE") <programlisting language="JAVA" role="JAVA">@Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_STORE")
public Integer getId() { ... } </programlisting> public Integer getId() { ... } </programlisting>
<para>The next example uses the identity generator:</para> <para>The next example uses the identity generator:</para>
<programlisting role="JAVA" language="JAVA">@Id @GeneratedValue(strategy=GenerationType.IDENTITY) <programlisting language="JAVA" role="JAVA">@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
public Long getId() { ... } </programlisting> public Long getId() { ... } </programlisting>
<para>The <literal>AUTO</literal> generator is the preferred type for <para>The <literal>AUTO</literal> generator is the preferred type for
@ -711,7 +712,7 @@ public Long getId() { ... } </programlisting>
Application level generators are defined at XML level (see <xref Application level generators are defined at XML level (see <xref
linkend="xml-overriding" />):</para> linkend="xml-overriding" />):</para>
<programlisting role="JAVA" language="JAVA">&lt;table-generator name="EMP_GEN" <programlisting language="JAVA" role="JAVA">&lt;table-generator name="EMP_GEN"
table="GENERATOR_TABLE" table="GENERATOR_TABLE"
pk-column-name="key" pk-column-name="key"
value-column-name="hi" value-column-name="hi"
@ -782,7 +783,7 @@ public Long getId() { ... } </programlisting>
<para>The next example shows the definition of a sequence generator in <para>The next example shows the definition of a sequence generator in
a class scope:</para> a class scope:</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
@javax.persistence.SequenceGenerator( @javax.persistence.SequenceGenerator(
name="SEQ_STORE", name="SEQ_STORE",
sequenceName="my_sequence" sequenceName="my_sequence"
@ -805,7 +806,7 @@ public class Store implements Serializable {
foreign generator but the JPA mapping reads better and is foreign generator but the JPA mapping reads better and is
encouraged.</para> encouraged.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
class MedicalHistory implements Serializable { class MedicalHistory implements Serializable {
@Id @OneToOne @Id @OneToOne
@JoinColumn(name = "person_id") @JoinColumn(name = "person_id")
@ -819,7 +820,7 @@ public class Person implements Serializable {
<para>Or alternatively</para> <para>Or alternatively</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
class MedicalHistory implements Serializable { class MedicalHistory implements Serializable {
@Id Integer id; @Id Integer id;
@ -891,7 +892,7 @@ class Person {
<para>Here is a simple example of <para>Here is a simple example of
<classname>@EmbeddedId</classname>.</para> <classname>@EmbeddedId</classname>.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
class User { class User {
@EmbeddedId @EmbeddedId
@AttributeOverride(name="firstName", column=@Column(name="fld_firstname") @AttributeOverride(name="firstName", column=@Column(name="fld_firstname")
@ -913,7 +914,7 @@ class UserId implements Serializable {
<para>An embedded id can itself contains the primary key of an <para>An embedded id can itself contains the primary key of an
associated entity.</para> associated entity.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
class Customer { class Customer {
@EmbeddedId CustomerId id; @EmbeddedId CustomerId id;
boolean preferredCustomer; boolean preferredCustomer;
@ -969,7 +970,7 @@ class UserId implements Serializable {
association directly in the embedded id component (instead of having association directly in the embedded id component (instead of having
to use the <classname>@MapsId</classname> annotation).</para> to use the <classname>@MapsId</classname> annotation).</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
class Customer { class Customer {
@EmbeddedId CustomerId id; @EmbeddedId CustomerId id;
boolean preferredCustomer; boolean preferredCustomer;
@ -1007,7 +1008,7 @@ class UserId implements Serializable {
approach is only supported by Hibernate but does not require an approach is only supported by Hibernate but does not require an
extra embeddable component.</para> extra embeddable component.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
class Customer implements Serializable { class Customer implements Serializable {
@Id @OneToOne @Id @OneToOne
@JoinColumns({ @JoinColumns({
@ -1055,7 +1056,7 @@ class UserId implements Serializable {
and Hibernate supports it.</para> and Hibernate supports it.</para>
</warning> </warning>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
class Customer { class Customer {
@Id @OneToOne @Id @OneToOne
@JoinColumns({ @JoinColumns({
@ -1095,7 +1096,7 @@ class UserId implements Serializable {
vanilla associated property in the vanilla associated property in the
<classname>@IdClass</classname>.</para> <classname>@IdClass</classname>.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
class Customer { class Customer {
@Id @OneToOne @Id @OneToOne
@JoinColumns({ @JoinColumns({
@ -1141,7 +1142,7 @@ class UserId implements Serializable {
this feature.</para> this feature.</para>
</warning> </warning>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class CustomerInventory implements Serializable { public class CustomerInventory implements Serializable {
@Id @Id
@TableGenerator(name = "inventory", @TableGenerator(name = "inventory",
@ -1210,7 +1211,7 @@ public class Customer implements Serializable {
UNION</literal> queries. It is commonly used for the top level of an UNION</literal> queries. It is commonly used for the top level of an
inheritance hierarchy:</para> inheritance hierarchy:</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Flight implements Serializable { ... } </programlisting> public class Flight implements Serializable { ... } </programlisting>
@ -1229,7 +1230,7 @@ public class Flight implements Serializable { ... } </programlisting>
same table, instances are distinguished by a special discriminator same table, instances are distinguished by a special discriminator
column:</para> column:</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE) @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn( @DiscriminatorColumn(
name="planetype", name="planetype",
@ -1269,7 +1270,7 @@ public class A320 extends Plane { ... } </programlisting>
<literal>@PrimaryKeyJoinColumns</literal> annotations define the <literal>@PrimaryKeyJoinColumns</literal> annotations define the
primary key(s) of the joined subclass table:</para> primary key(s) of the joined subclass table:</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
@Inheritance(strategy=InheritanceType.JOINED) @Inheritance(strategy=InheritanceType.JOINED)
public class Boat implements Serializable { ... } public class Boat implements Serializable { ... }
@ -1296,7 +1297,7 @@ public class AmericaCupClass extends Boat { ... } </programlisting>
mapped entity (ie no specific table for this entity). For that purpose mapped entity (ie no specific table for this entity). For that purpose
you can map them as <literal>@MappedSuperclass</literal>.</para> you can map them as <literal>@MappedSuperclass</literal>.</para>
<programlisting role="JAVA" language="JAVA">@MappedSuperclass <programlisting language="JAVA" role="JAVA">@MappedSuperclass
public class BaseEntity { public class BaseEntity {
@Basic @Basic
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
@ -1351,7 +1352,7 @@ public class BaseEntity {
root entity level using the <literal>@AttributeOverride</literal> root entity level using the <literal>@AttributeOverride</literal>
annotation.</para> annotation.</para>
<programlisting role="JAVA" language="JAVA">@MappedSuperclass <programlisting language="JAVA" role="JAVA">@MappedSuperclass
public class FlyingObject implements Serializable { public class FlyingObject implements Serializable {
public int getAltitude() { public int getAltitude() {
@ -1412,7 +1413,7 @@ public class Plane extends FlyingObject {
<para>First, we map a real one-to-one association using shared primary <para>First, we map a real one-to-one association using shared primary
keys:</para> keys:</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Body { public class Body {
@Id @Id
public Long getId() { return id; } public Long getId() { return id; }
@ -1425,7 +1426,7 @@ public class Body {
... ...
} </programlisting> } </programlisting>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Heart { public class Heart {
@Id @Id
public Long getId() { ...} public Long getId() { ...}
@ -1438,7 +1439,7 @@ public class Heart {
<para>In the following example, the associated entities are linked <para>In the following example, the associated entities are linked
through an explicit foreign key column:</para> through an explicit foreign key column:</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Customer implements Serializable { public class Customer implements Serializable {
@OneToOne(cascade = CascadeType.ALL) @OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name="passport_fk") @JoinColumn(name="passport_fk")
@ -1492,7 +1493,7 @@ public class Passport implements Serializable {
<para>The third possibility (using an association table) is quite <para>The third possibility (using an association table) is quite
exotic.</para> exotic.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Customer implements Serializable { public class Customer implements Serializable {
@OneToOne(cascade = CascadeType.ALL) @OneToOne(cascade = CascadeType.ALL)
@JoinTable(name = "CustomerPassports", @JoinTable(name = "CustomerPassports",
@ -1530,7 +1531,7 @@ public class Passport implements Serializable {
<para>Many-to-one associations are declared at the property level with <para>Many-to-one associations are declared at the property level with
the annotation <literal>@ManyToOne</literal>:</para> the annotation <literal>@ManyToOne</literal>:</para>
<programlisting role="JAVA" language="JAVA">@Entity() <programlisting language="JAVA" role="JAVA">@Entity()
public class Flight implements Serializable { public class Flight implements Serializable {
@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} ) @ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
@JoinColumn(name="COMP_ID") @JoinColumn(name="COMP_ID")
@ -1555,7 +1556,7 @@ public class Flight implements Serializable {
almost all cases. However this is useful when you want to use almost all cases. However this is useful when you want to use
interfaces as the return type instead of the regular entity.</para> interfaces as the return type instead of the regular entity.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Flight implements Serializable { public class Flight implements Serializable {
@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE}, targetEntity=CompanyImpl.class ) @ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE}, targetEntity=CompanyImpl.class )
@JoinColumn(name="COMP_ID") @JoinColumn(name="COMP_ID")
@ -1577,7 +1578,7 @@ public interface Company {
referencing the target entity table (through referencing the target entity table (through
<literal>@JoinTable.inverseJoinColumns</literal>).</para> <literal>@JoinTable.inverseJoinColumns</literal>).</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Flight implements Serializable { public class Flight implements Serializable {
@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} ) @ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
@JoinTable(name="Flight_Company", @JoinTable(name="Flight_Company",
@ -1619,7 +1620,7 @@ public class Flight implements Serializable {
association is annotated by association is annotated by
<literal>@OneToMany(mappedBy=...)</literal></para> <literal>@OneToMany(mappedBy=...)</literal></para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Troop { public class Troop {
@OneToMany(mappedBy="troop") @OneToMany(mappedBy="troop")
public Set&lt;Soldier&gt; getSoldiers() { public Set&lt;Soldier&gt; getSoldiers() {
@ -1647,7 +1648,7 @@ public class Soldier {
false. This solution is not optimized and will produce some false. This solution is not optimized and will produce some
additional UPDATE statements.</para> additional UPDATE statements.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Troop { public class Troop {
@OneToMany @OneToMany
@JoinColumn(name="troop_fk") //we need to duplicate the physical information @JoinColumn(name="troop_fk") //we need to duplicate the physical information
@ -1674,7 +1675,7 @@ public class Soldier {
association is described through a association is described through a
<literal>@JoinColumn</literal></para> <literal>@JoinColumn</literal></para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Customer implements Serializable { public class Customer implements Serializable {
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER) @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
@JoinColumn(name="CUST_ID") @JoinColumn(name="CUST_ID")
@ -1699,7 +1700,7 @@ public class Ticket implements Serializable {
preferred. This association is described through an preferred. This association is described through an
<literal>@JoinTable</literal>.</para> <literal>@JoinTable</literal>.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Trainer { public class Trainer {
@OneToMany @OneToMany
@JoinTable( @JoinTable(
@ -1740,7 +1741,7 @@ public class Monkey {
added to the foreign key referencing the other side table to added to the foreign key referencing the other side table to
reflect the one to many.</para> reflect the one to many.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Trainer { public class Trainer {
@OneToMany @OneToMany
public Set&lt;Tiger&gt; getTrainedTigers() { public Set&lt;Tiger&gt; getTrainedTigers() {
@ -1776,7 +1777,7 @@ public class Tiger {
the inverse end (ie. it will be ignored when updating the the inverse end (ie. it will be ignored when updating the
relationship values in the association table):</para> relationship values in the association table):</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Employer implements Serializable { public class Employer implements Serializable {
@ManyToMany( @ManyToMany(
targetEntity=org.hibernate.test.metadata.manytomany.Employee.class, targetEntity=org.hibernate.test.metadata.manytomany.Employee.class,
@ -1793,7 +1794,7 @@ public class Employer implements Serializable {
... ...
} </programlisting> } </programlisting>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Employee implements Serializable { public class Employee implements Serializable {
@ManyToMany( @ManyToMany(
cascade = {CascadeType.PERSIST, CascadeType.MERGE}, cascade = {CascadeType.PERSIST, CascadeType.MERGE},
@ -1835,7 +1836,7 @@ public class Employee implements Serializable {
and the other side primary key column(s). These are the same rules and the other side primary key column(s). These are the same rules
used for a unidirectional one to many relationship.</para> used for a unidirectional one to many relationship.</para>
<programlisting role="JAVA" language="JAVA"> <programlisting language="JAVA" role="JAVA">
@Entity @Entity
public class Store { public class Store {
@ManyToMany(cascade = CascadeType.PERSIST) @ManyToMany(cascade = CascadeType.PERSIST)
@ -1867,7 +1868,7 @@ public class City {
the other side primary key column(s). These are the same rules the other side primary key column(s). These are the same rules
used for a unidirectional one to many relationship.</para> used for a unidirectional one to many relationship.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Store { public class Store {
@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}) @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
public Set&lt;Customer&gt; getCustomers() { public Set&lt;Customer&gt; getCustomers() {
@ -1899,7 +1900,7 @@ public class Customer {
objects. Use the <classname>@ElementCollection</classname> in this objects. Use the <classname>@ElementCollection</classname> in this
case.</para> case.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class User { public class User {
[...] [...]
public String getLastname() { ...} public String getLastname() { ...}
@ -1927,7 +1928,7 @@ public class User {
embeddable object in the collection table, use the embeddable object in the collection table, use the
<classname>@AttributeOverride</classname> annotation.</para> <classname>@AttributeOverride</classname> annotation.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class User { public class User {
[...] [...]
public String getLastname() { ...} public String getLastname() { ...}
@ -1956,7 +1957,7 @@ public class Address {
<literal>key.</literal> prefix to override properties of the <literal>key.</literal> prefix to override properties of the
embeddable object used in the map key.</para> embeddable object used in the map key.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class User { public class User {
@ElementCollection @ElementCollection
@AttributeOverrides({ @AttributeOverrides({
@ -1999,7 +2000,7 @@ public class User {
collection will be ordered by the primary key of the target collection will be ordered by the primary key of the target
entity.</para> entity.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Customer { public class Customer {
@Id @GeneratedValue public Integer getId() { return id; } @Id @GeneratedValue public Integer getId() { return id; }
public void setId(Integer id) { this.id = id; } public void setId(Integer id) { this.id = id; }
@ -2047,7 +2048,7 @@ public class Order {
<literal>ORDER</literal> (in the following example, it would be <literal>ORDER</literal> (in the following example, it would be
<literal>orders_ORDER</literal>).</para> <literal>orders_ORDER</literal>).</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Customer { public class Customer {
@Id @GeneratedValue public Integer getId() { return id; } @Id @GeneratedValue public Integer getId() { return id; }
public void setId(Integer id) { this.id = id; } public void setId(Integer id) { this.id = id; }
@ -2112,7 +2113,7 @@ public class Order {
other words, if you change the property value, the key will not other words, if you change the property value, the key will not
change automatically in your Java model.</para> change automatically in your Java model.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Customer { public class Customer {
@Id @GeneratedValue public Integer getId() { return id; } @Id @GeneratedValue public Integer getId() { return id; }
public void setId(Integer id) { this.id = id; } public void setId(Integer id) { this.id = id; }
@ -2187,7 +2188,7 @@ public class Order {
should wonder why at this day and age you don't use should wonder why at this day and age you don't use
generics).</para> generics).</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Customer { public class Customer {
@Id @GeneratedValue public Integer getId() { return id; } @Id @GeneratedValue public Integer getId() { return id; }
public void setId(Integer id) { this.id = id; } public void setId(Integer id) { this.id = id; }
@ -2375,7 +2376,7 @@ public class Order {
to true. In a way, it means that the associated entity's lifecycle is to true. In a way, it means that the associated entity's lifecycle is
bound to the owning entity just like an embeddable object is.</para> bound to the owning entity just like an embeddable object is.</para>
<programlisting role="JAVA" language="JAVA">@Entity class Customer { <programlisting language="JAVA" role="JAVA">@Entity class Customer {
@OneToMany(orphanRemoval=true) public Set&lt;Order&gt; getOrders() { return orders; } @OneToMany(orphanRemoval=true) public Set&lt;Order&gt; getOrders() { return orders; }
public void setOrders(Set&lt;Order&gt; orders) { this.orders = orders; } public void setOrders(Set&lt;Order&gt; orders) { this.orders = orders; }
private Set&lt;Order&gt; orders; private Set&lt;Order&gt; orders;
@ -2428,7 +2429,7 @@ customer.getOrders().remove(order); //order will be deleted by cascade</programl
You can also use <literal>@IdClass</literal>. These are more detailed in You can also use <literal>@IdClass</literal>. These are more detailed in
<xref linkend="entity-mapping-identifier" />.</para> <xref linkend="entity-mapping-identifier" />.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class RegionalArticle implements Serializable { public class RegionalArticle implements Serializable {
@Id @Id
@ -2440,7 +2441,7 @@ public class RegionalArticlePk implements Serializable { ... } </programli
<para>or alternatively</para> <para>or alternatively</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class RegionalArticle implements Serializable { public class RegionalArticle implements Serializable {
@EmbeddedId @EmbeddedId
@ -2458,7 +2459,7 @@ public class RegionalArticlePk implements Serializable { ... } </program
explicitly. Otherwise, Hibernate will suppose that you use the same explicitly. Otherwise, Hibernate will suppose that you use the same
order of columns as in the primary key declaration.</para> order of columns as in the primary key declaration.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Parent implements Serializable { public class Parent implements Serializable {
@Id @Id
public ParentPk id; public ParentPk id;
@ -2474,7 +2475,7 @@ public class Parent implements Serializable {
... ...
} </programlisting> } </programlisting>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Child implements Serializable { public class Child implements Serializable {
@Id @GeneratedValue @Id @GeneratedValue
public Integer id; public Integer id;
@ -2488,7 +2489,7 @@ public class Child implements Serializable {
public Parent parent; //unidirectional public Parent parent; //unidirectional
} </programlisting> } </programlisting>
<programlisting role="JAVA" language="JAVA">@Embeddable <programlisting language="JAVA" role="JAVA">@Embeddable
public class ParentPk implements Serializable { public class ParentPk implements Serializable {
String firstName; String firstName;
String lastName; String lastName;
@ -2509,7 +2510,7 @@ public class ParentPk implements Serializable {
parameter of <literal>@Column</literal> or parameter of <literal>@Column</literal> or
<literal>@JoinColumn</literal>.</para> <literal>@JoinColumn</literal>.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
@Table(name="MainCat") @Table(name="MainCat")
@SecondaryTables({ @SecondaryTables({
@SecondaryTable(name="Cat1", pkJoinColumns={ @SecondaryTable(name="Cat1", pkJoinColumns={
@ -2623,7 +2624,7 @@ public class Cat implements Serializable {
that.</para> that.</para>
</note> </note>
<programlisting role="JAVA" language="JAVA">@Entity @Cacheable <programlisting language="JAVA" role="JAVA">@Entity @Cacheable
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Forest { ... }</programlisting> public class Forest { ... }</programlisting>
@ -2632,7 +2633,7 @@ public class Forest { ... }</programlisting>
<classname>@Cache</classname> annotation on the collection <classname>@Cache</classname> annotation on the collection
property.</para> property.</para>
<programlisting role="JAVA" language="JAVA">@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER) <programlisting language="JAVA" role="JAVA">@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
@JoinColumn(name="CUST_ID") @JoinColumn(name="CUST_ID")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public SortedSet&lt;Ticket&gt; getTickets() { public SortedSet&lt;Ticket&gt; getTickets() {
@ -2651,7 +2652,7 @@ public SortedSet&lt;Ticket&gt; getTickets() {
<area coords="4 55" id="cache-hm3" /> <area coords="4 55" id="cache-hm3" />
</areaspec> </areaspec>
<programlisting role="JAVA" language="JAVA">@Cache( <programlisting language="JAVA" role="JAVA">@Cache(
CacheConcurrencyStrategy usage(); CacheConcurrencyStrategy usage();
String region() default ""; String region() default "";
String include() default "all"; String include() default "all";
@ -2708,7 +2709,7 @@ public SortedSet&lt;Ticket&gt; getTickets() {
manager factory scope. A named query is defined by its name and the manager factory scope. A named query is defined by its name and the
actual query string.</para> actual query string.</para>
<programlisting role="JAVA" language="JAVA">&lt;entity-mappings&gt; <programlisting language="JAVA" role="JAVA">&lt;entity-mappings&gt;
&lt;named-query name="plane.getAll"&gt; &lt;named-query name="plane.getAll"&gt;
&lt;query&gt;select p from Plane p&lt;/query&gt; &lt;query&gt;select p from Plane p&lt;/query&gt;
&lt;/named-query&gt; &lt;/named-query&gt;
@ -2738,7 +2739,6 @@ public class MyDao {
<para>The available Hibernate hints are</para> <para>The available Hibernate hints are</para>
<table> <table>
<title>Query hints</title> <title>Query hints</title>
@ -2837,7 +2837,7 @@ public class MyDao {
definitions are optional provided that they map to the same column name definitions are optional provided that they map to the same column name
as the one declared on the class property.</para> as the one declared on the class property.</para>
<programlisting role="JAVA" language="JAVA">@NamedNativeQuery(name="night&amp;area", query="select night.id nid, night.night_duration, " <programlisting language="JAVA" role="JAVA">@NamedNativeQuery(name="night&amp;area", query="select night.id nid, night.night_duration, "
+ " night.night_date, area.id aid, night.area_id, area.name " + " night.night_date, area.id aid, night.area_id, area.name "
+ "from Night night, Area area where night.area_id = area.id", + "from Night night, Area area where night.area_id = area.id",
resultSetMapping="joinMapping") resultSetMapping="joinMapping")
@ -2863,7 +2863,7 @@ public class MyDao {
column name, actually the column name retrieved by the query. Let's now column name, actually the column name retrieved by the query. Let's now
see an implicit declaration of the property / column.</para> see an implicit declaration of the property / column.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
@SqlResultSetMapping(name="implicit", @SqlResultSetMapping(name="implicit",
entities=@EntityResult(entityClass=SpaceShip.class)) entities=@EntityResult(entityClass=SpaceShip.class))
@NamedNativeQuery(name="implicitSample", @NamedNativeQuery(name="implicitSample",
@ -2911,7 +2911,7 @@ public class SpaceShip {
property name for the relationship, followed by a dot ("."), followed by property name for the relationship, followed by a dot ("."), followed by
the name or the field or property of the primary key.</para> the name or the field or property of the primary key.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
@SqlResultSetMapping(name="compositekey", @SqlResultSetMapping(name="compositekey",
entities=@EntityResult(entityClass=SpaceShip.class, entities=@EntityResult(entityClass=SpaceShip.class,
fields = { fields = {
@ -3014,7 +3014,7 @@ public class Captain implements Serializable {
mapping, you can use the <literal>resultClass</literal> attribute mapping, you can use the <literal>resultClass</literal> attribute
instead of <literal>resultSetMapping</literal>:</para> instead of <literal>resultSetMapping</literal>:</para>
<programlisting role="JAVA" language="JAVA">@NamedNativeQuery(name="implicitSample", query="select * from SpaceShip", <programlisting language="JAVA" role="JAVA">@NamedNativeQuery(name="implicitSample", query="select * from SpaceShip",
resultClass=SpaceShip.class) resultClass=SpaceShip.class)
public class SpaceShip {</programlisting> public class SpaceShip {</programlisting>
@ -3025,7 +3025,7 @@ public class SpaceShip {</programlisting>
and scalar returns in the same native query (this is probably not that and scalar returns in the same native query (this is probably not that
common though).</para> common though).</para>
<programlisting role="JAVA" language="JAVA">@SqlResultSetMapping(name="scalar", columns=@ColumnResult(name="dimension")) <programlisting language="JAVA" role="JAVA">@SqlResultSetMapping(name="scalar", columns=@ColumnResult(name="dimension"))
@NamedNativeQuery(name="scalar", query="select length*width as dimension from SpaceShip", resultSetMapping="scalar")</programlisting> @NamedNativeQuery(name="scalar", query="select length*width as dimension from SpaceShip", resultSetMapping="scalar")</programlisting>
<para>An other query hint specific to native queries has been <para>An other query hint specific to native queries has been
@ -3187,7 +3187,7 @@ public class SpaceShip {</programlisting>
implements persistence via, for example, stored procedure calls, implements persistence via, for example, stored procedure calls,
serialization to flat files or LDAP.</para> serialization to flat files or LDAP.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
@BatchSize(size=5) @BatchSize(size=5)
@org.hibernate.annotations.Entity( @org.hibernate.annotations.Entity(
selectBeforeUpdate = true, selectBeforeUpdate = true,
@ -3197,7 +3197,9 @@ public class SpaceShip {</programlisting>
@Where(clause="1=1") @Where(clause="1=1")
@org.hibernate.annotations.Table(name="Forest", indexes = { @Index(name="idx", columnNames = { "name", "length" } ) } ) @org.hibernate.annotations.Table(name="Forest", indexes = { @Index(name="idx", columnNames = { "name", "length" } ) } )
@Persister(impl=MyEntityPersister.class) @Persister(impl=MyEntityPersister.class)
public class Forest { ... }</programlisting> <programlisting role="JAVA" language="JAVA">@Entity public class Forest { ... }</programlisting>
<programlisting language="JAVA" role="JAVA">@Entity
@Inheritance( @Inheritance(
strategy=InheritanceType.JOINED strategy=InheritanceType.JOINED
) )
@ -3222,7 +3224,7 @@ public class Carrot extends Vegetable { ... }</programlisting>
allows you to define an Hibernate specific id allows you to define an Hibernate specific id
generator.</literal></para> generator.</literal></para>
<programlisting role="JAVA" language="JAVA">@Id @GeneratedValue(generator="system-uuid") <programlisting language="JAVA" role="JAVA">@Id @GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid", strategy = "uuid") @GenericGenerator(name="system-uuid", strategy = "uuid")
public String getId() { public String getId() {
@ -3247,7 +3249,7 @@ public Integer getId() {</programlisting>
annotations, making them application level generators (just like if annotations, making them application level generators (just like if
they were in a JPA XML file).</para> they were in a JPA XML file).</para>
<programlisting role="JAVA" language="JAVA">@GenericGenerators( <programlisting language="JAVA" role="JAVA">@GenericGenerators(
{ {
@GenericGenerator( @GenericGenerator(
name="hibseq", name="hibseq",
@ -3275,7 +3277,7 @@ package org.hibernate.test.model</programlisting>
composed of all the properties marked composed of all the properties marked
<classname>@NaturalId</classname>.</para> <classname>@NaturalId</classname>.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Citizen { public class Citizen {
@Id @Id
@GeneratedValue @GeneratedValue
@ -3317,7 +3319,7 @@ List results = s.createCriteria( Citizen.class )
property into a column. This kind of property is read only (its value property into a column. This kind of property is read only (its value
is calculated by your formula fragment).</para> is calculated by your formula fragment).</para>
<programlisting role="JAVA" language="JAVA">@Formula("obj_length * obj_height * obj_width") <programlisting language="JAVA" role="JAVA">@Formula("obj_length * obj_height * obj_width")
public long getObjectVolume()</programlisting> public long getObjectVolume()</programlisting>
<para>The SQL fragment can be as complex as you want and even include <para>The SQL fragment can be as complex as you want and even include
@ -3353,7 +3355,7 @@ public long getObjectVolume()</programlisting>
Place your annotations before the package declaration.</para> Place your annotations before the package declaration.</para>
</note> </note>
<programlisting role="JAVA" language="JAVA">@TypeDef( <programlisting language="JAVA" role="JAVA">@TypeDef(
name = "phoneNumber", name = "phoneNumber",
defaultForType = PhoneNumber.class, defaultForType = PhoneNumber.class,
typeClass = PhoneNumberType.class typeClass = PhoneNumberType.class
@ -3372,7 +3374,7 @@ public class ContactDetails {
<literal>parameters</literal> attribute to customize the <literal>parameters</literal> attribute to customize the
TypeDef.</para> TypeDef.</para>
<programlisting role="JAVA" language="JAVA">//in org/hibernate/test/annotations/entity/package-info.java <programlisting language="JAVA" role="JAVA">//in org/hibernate/test/annotations/entity/package-info.java
@TypeDefs( @TypeDefs(
{ {
@TypeDef( @TypeDef(
@ -3397,7 +3399,7 @@ public class Forest {
definitions. The <literal>@Columns</literal> has been introduced for definitions. The <literal>@Columns</literal> has been introduced for
that purpose.</para> that purpose.</para>
<programlisting role="JAVA" language="JAVA">@Type(type="org.hibernate.test.annotations.entity.MonetaryAmountUserType") <programlisting language="JAVA" role="JAVA">@Type(type="org.hibernate.test.annotations.entity.MonetaryAmountUserType")
@Columns(columns = { @Columns(columns = {
@Column(name="r_amount"), @Column(name="r_amount"),
@Column(name="r_currency") @Column(name="r_currency")
@ -3421,7 +3423,7 @@ public class MonetaryAmount implements Serializable {
<literal>@Index</literal> annotation on a one column property, the <literal>@Index</literal> annotation on a one column property, the
columnNames attribute will then be ignored</para> columnNames attribute will then be ignored</para>
<programlisting role="JAVA" language="JAVA">@Column(secondaryTable="Cat1") <programlisting language="JAVA" role="JAVA">@Column(secondaryTable="Cat1")
@Index(name="story1index") @Index(name="story1index")
public String getStoryPart1() { public String getStoryPart1() {
return storyPart1; return storyPart1;
@ -3434,7 +3436,7 @@ public String getStoryPart1() {
<para>When inside an embeddable object, you can define one of the <para>When inside an embeddable object, you can define one of the
properties as a pointer back to the owner element.</para> properties as a pointer back to the owner element.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Person { public class Person {
@Embeddable public Address address; @Embeddable public Address address;
... ...
@ -3457,7 +3459,7 @@ person == person.address.owner</programlisting>
database. Hibernate can deal with such properties and triggers a database. Hibernate can deal with such properties and triggers a
subsequent select to read these properties.</para> subsequent select to read these properties.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Antenna { public class Antenna {
@Id public Integer id; @Id public Integer id;
@Generated(GenerationTime.ALWAYS) @Generated(GenerationTime.ALWAYS)
@ -3491,7 +3493,7 @@ public class Antenna {
<literal>targetEntity</literal> attribute available on <literal>targetEntity</literal> attribute available on
associations.</para> associations.</para>
<programlisting role="JAVA" language="JAVA"> @Embedded <programlisting language="JAVA" role="JAVA"> @Embedded
@Target(OwnerImpl.class) @Target(OwnerImpl.class)
public Owner getOwner() { public Owner getOwner() {
return owner; return owner;
@ -3523,7 +3525,7 @@ public class Antenna {
formula for discriminator resolution (no need to have a dedicated formula for discriminator resolution (no need to have a dedicated
column).</para> column).</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
@DiscriminatorFormula("case when forest_type is null then 0 else forest_type end") @DiscriminatorFormula("case when forest_type is null then 0 else forest_type end")
public class Forest { ... }</programlisting> public class Forest { ... }</programlisting>
@ -3538,7 +3540,7 @@ public class Forest { ... }</programlisting>
<para>You can define the foreign key name generated by Hibernate for <para>You can define the foreign key name generated by Hibernate for
subclass tables in the JOINED inheritance strategy.</para> subclass tables in the JOINED inheritance strategy.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
@Inheritance(strategy = InheritanceType.JOINED) @Inheritance(strategy = InheritanceType.JOINED)
public abstract class File { ... } public abstract class File { ... }
@ -3564,7 +3566,7 @@ public class Document extends File {</programlisting>
<literal>@ManyToOne</literal>, <literal>@OneToMany</literal> or <literal>@ManyToOne</literal>, <literal>@OneToMany</literal> or
<literal>@ManyToMany</literal> association.</para> <literal>@ManyToMany</literal> association.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Child { public class Child {
... ...
@ManyToOne @ManyToOne
@ -3576,7 +3578,7 @@ public class Child {
<para>Sometimes you want to delegate to your database the deletion of <para>Sometimes you want to delegate to your database the deletion of
cascade when a given entity is deleted.</para> cascade when a given entity is deleted.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Child { public class Child {
... ...
@ManyToOne @ManyToOne
@ -3592,7 +3594,7 @@ public class Child {
fairly unreadable name. You can override the constraint name by use fairly unreadable name. You can override the constraint name by use
<literal>@ForeignKey</literal>.</para> <literal>@ForeignKey</literal>.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Child { public class Child {
... ...
@ManyToOne @ManyToOne
@ -3722,7 +3724,7 @@ alter table Child add constraint FK_PARENT foreign key (parent_id) references Pa
<classname>@AnyDef</classname> and <classname>@AnyDefs</classname> <classname>@AnyDef</classname> and <classname>@AnyDefs</classname>
annotations are used.</para> annotations are used.</para>
<programlisting role="JAVA" language="JAVA"> @Any( metaColumn = @Column( name = "property_type" ), fetch=FetchType.EAGER ) <programlisting language="JAVA" role="JAVA"> @Any( metaColumn = @Column( name = "property_type" ), fetch=FetchType.EAGER )
@AnyMetaDef( @AnyMetaDef(
idType = "integer", idType = "integer",
metaType = "string", metaType = "string",
@ -3743,7 +3745,7 @@ alter table Child add constraint FK_PARENT foreign key (parent_id) references Pa
reused. It is recommended to place it as a package metadata in this reused. It is recommended to place it as a package metadata in this
case.</para> case.</para>
<programlisting role="JAVA" language="JAVA">//on a package <programlisting language="JAVA" role="JAVA">//on a package
@AnyMetaDef( name="property" @AnyMetaDef( name="property"
idType = "integer", idType = "integer",
metaType = "string", metaType = "string",
@ -3816,7 +3818,7 @@ package org.hibernate.test.annotations.any;
<classname>SortedSet</classname> or a <classname>SortedMap</classname> <classname>SortedSet</classname> or a <classname>SortedMap</classname>
interface.</para> interface.</para>
<programlisting role="JAVA" language="JAVA"> @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER) <programlisting language="JAVA" role="JAVA"> @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
@JoinColumn(name="CUST_ID") @JoinColumn(name="CUST_ID")
@Sort(type = SortType.COMPARATOR, comparator = TicketComparator.class) @Sort(type = SortType.COMPARATOR, comparator = TicketComparator.class)
@Where(clause="1=1") @Where(clause="1=1")
@ -3835,7 +3837,7 @@ package org.hibernate.test.annotations.any;
<literal>inverseName</literal> referencing to the other side <literal>inverseName</literal> referencing to the other side
constraint.</para> constraint.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Woman { public class Woman {
... ...
@ManyToMany(cascade = {CascadeType.ALL}) @ManyToMany(cascade = {CascadeType.ALL})
@ -3861,7 +3863,7 @@ alter table Man_Woman add constraint TO_MAN_FK foreign key (man_id) references M
associated class explicitly maps the indexed value, the use of associated class explicitly maps the indexed value, the use of
<methodname>mappedBy</methodname> is permitted:</para> <methodname>mappedBy</methodname> is permitted:</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Parent { public class Parent {
@OneToMany(mappedBy="parent") @OneToMany(mappedBy="parent")
@OrderColumn(name="order") @OrderColumn(name="order")
@ -3889,7 +3891,7 @@ public class Child {
the collection as <literal>mappedBy</literal>. Instead, we could use the collection as <literal>mappedBy</literal>. Instead, we could use
the following mapping:</para> the following mapping:</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
public class Parent { public class Parent {
@OneToMany @OneToMany
@OrderColumn(name="order") @OrderColumn(name="order")
@ -3925,7 +3927,7 @@ public class Child {
generator strategy. The strategy can be <literal>identity</literal>, generator strategy. The strategy can be <literal>identity</literal>,
or any defined generator name of your application.</para> or any defined generator name of your application.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
@TableGenerator(name="ids_generator", table="IDS") @TableGenerator(name="ids_generator", table="IDS")
public class Passport { public class Passport {
... ...
@ -3955,7 +3957,7 @@ public class Passport {
only in very special cases (eg. audit logs, user session data, only in very special cases (eg. audit logs, user session data,
etc).</para> etc).</para>
<programlisting role="JAVA" language="JAVA"> @ManyToAny( <programlisting language="JAVA" role="JAVA"> @ManyToAny(
metaColumn = @Column( name = "property_type" ) ) metaColumn = @Column( name = "property_type" ) )
@AnyMetaDef( @AnyMetaDef(
idType = "integer", idType = "integer",
@ -4033,7 +4035,7 @@ public class Passport {
<literal>PERSIST</literal> at flush time as per the <literal>PERSIST</literal> at flush time as per the
specification).</para> specification).</para>
<programlisting role="JAVA" language="JAVA">@OneToMany( cascade = {CascadeType.PERSIST, CascadeType.MERGE} ) <programlisting language="JAVA" role="JAVA">@OneToMany( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
@Cascade(org.hibernate.annotations.CascadeType.REPLICATE) @Cascade(org.hibernate.annotations.CascadeType.REPLICATE)
public Collection&lt;Employer&gt; getEmployers()</programlisting> public Collection&lt;Employer&gt; getEmployers()</programlisting>
@ -4065,7 +4067,7 @@ public Collection&lt;Employer&gt; getEmployers()</programlisting>
entity load or the collection load. <literal>@Filter</literal> is used entity load or the collection load. <literal>@Filter</literal> is used
and placed either on the entity or the collection element</para> and placed either on the entity or the collection element</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
@FilterDef(name="minLength", parameters=@ParamDef( name="minLength", type="integer" ) ) @FilterDef(name="minLength", parameters=@ParamDef( name="minLength", type="integer" ) )
@Filters( { @Filters( {
@Filter(name="betweenLength", condition=":minLength &lt;= length and :maxLength &gt;= length"), @Filter(name="betweenLength", condition=":minLength &lt;= length and :maxLength &gt;= length"),
@ -4081,7 +4083,7 @@ public class Forest { ... }</programlisting>
association table, use the <literal>@FilterJoinTable</literal> association table, use the <literal>@FilterJoinTable</literal>
annotation.</para> annotation.</para>
<programlisting role="JAVA" language="JAVA"> @OneToMany <programlisting language="JAVA" role="JAVA"> @OneToMany
@JoinTable @JoinTable
//filter on the target entity table //filter on the target entity table
@Filter(name="betweenLength", condition=":minLength &lt;= length and :maxLength &gt;= length") @Filter(name="betweenLength", condition=":minLength &lt;= length and :maxLength &gt;= length")
@ -4159,7 +4161,7 @@ public class Forest { ... }</programlisting>
you can also override the SQL statement used to load or change the state you can also override the SQL statement used to load or change the state
of entities.</para> of entities.</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
@Table(name="CHAOS") @Table(name="CHAOS")
@SQLInsert( sql="INSERT INTO CHAOS(size, name, nickname, id) VALUES(?,upper(?),?,?)") @SQLInsert( sql="INSERT INTO CHAOS(size, name, nickname, id) VALUES(?,upper(?),?,?)")
@SQLUpdate( sql="UPDATE CHAOS SET size = ?, name = upper(?), nickname = ? WHERE id = ?") @SQLUpdate( sql="UPDATE CHAOS SET size = ?, name = upper(?), nickname = ? WHERE id = ?")
@ -4214,7 +4216,7 @@ public class Chaos {
<para>You can use the exact same set of annotations to override the <para>You can use the exact same set of annotations to override the
collection related statements.</para> collection related statements.</para>
<programlisting role="JAVA" language="JAVA">@OneToMany <programlisting language="JAVA" role="JAVA">@OneToMany
@JoinColumn(name="chaos_fk") @JoinColumn(name="chaos_fk")
@SQLInsert( sql="UPDATE CASIMIR_PARTICULE SET chaos_fk = ? where id = ?") @SQLInsert( sql="UPDATE CASIMIR_PARTICULE SET chaos_fk = ? where id = ?")
@SQLDelete( sql="UPDATE CASIMIR_PARTICULE SET chaos_fk = null where id = ?") @SQLDelete( sql="UPDATE CASIMIR_PARTICULE SET chaos_fk = null where id = ?")
@ -4234,7 +4236,7 @@ private Set&lt;CasimirParticle&gt; particles = new HashSet&lt;CasimirParticle&gt
all) attributes <literal>sqlInsert</literal>, all) attributes <literal>sqlInsert</literal>,
<literal>sqlUpdate</literal>, <literal>sqlDelete</literal>:</para> <literal>sqlUpdate</literal>, <literal>sqlDelete</literal>:</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
@SecondaryTables({ @SecondaryTables({
@SecondaryTable(name = "`Cat nbr1`"), @SecondaryTable(name = "`Cat nbr1`"),
@SecondaryTable(name = "Cat2"}) @SecondaryTable(name = "Cat2"})
@ -4274,7 +4276,7 @@ public class Cat implements Serializable {</programlisting>
<para>To define tuplixer in annotations, simply use the <para>To define tuplixer in annotations, simply use the
<literal>@Tuplizer</literal> annotation on the according element</para> <literal>@Tuplizer</literal> annotation on the according element</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
@Tuplizer(impl = DynamicEntityTuplizer.class) @Tuplizer(impl = DynamicEntityTuplizer.class)
public interface Cuisine { public interface Cuisine {
@Id @Id
@ -4304,7 +4306,7 @@ public interface Cuisine {
fetch profile will be in affect for that session until it is explicitly fetch profile will be in affect for that session until it is explicitly
disabled. Lets look at an example:</para> disabled. Lets look at an example:</para>
<programlisting role="JAVA" language="JAVA">@Entity <programlisting language="JAVA" role="JAVA">@Entity
@FetchProfile(name = "customer-with-orders", fetchOverrides = { @FetchProfile(name = "customer-with-orders", fetchOverrides = {
@FetchProfile.FetchOverride(entity = Customer.class, association = "orders", mode = FetchMode.JOIN) @FetchProfile.FetchOverride(entity = Customer.class, association = "orders", mode = FetchMode.JOIN)
}) })
@ -4323,12 +4325,13 @@ public class Customer {
// standard getter/setter // standard getter/setter
... ...
}</programlisting> }</programlisting>
<para>In the normal case the orders association would be lazy
loaded by Hibernate, but in a usecase where it is more efficient to load <para>In the normal case the orders association would be lazy loaded by
the customer and their orders together you could do something like Hibernate, but in a usecase where it is more efficient to load the
customer and their orders together you could do something like
this:</para> this:</para>
<programlisting role="JAVA" language="JAVA">Session session = ...; <programlisting language="JAVA" role="JAVA">Session session = ...;
session.enableFetchProfile( "customer-with-orders" ); // name matches @FetchProfile name session.enableFetchProfile( "customer-with-orders" ); // name matches @FetchProfile name
Customer customer = (Customer) session.get( Customer.class, customerId ); Customer customer = (Customer) session.get( Customer.class, customerId );
session.disableFetchProfile( "customer-with-orders" ); // or just close the session session.disableFetchProfile( "customer-with-orders" ); // or just close the session
@ -4350,4 +4353,4 @@ session.disableFetchProfile( "customer-with-orders" ); // or just close the sess
Hibernate Core documentation.</para> Hibernate Core documentation.</para>
</section> </section>
</section> </section>
</chapter> </chapter>

View File

@ -46,7 +46,7 @@
<para>Alternatively add the following dependency in your dependency <para>Alternatively add the following dependency in your dependency
manager (like Maven or Ivy). Here is an example</para> manager (like Maven or Ivy). Here is an example</para>
<programlisting role="XML" language="XML">&lt;project ...&gt; <programlisting language="XML" role="XML">&lt;project ...&gt;
... ...
&lt;dependencies&gt; &lt;dependencies&gt;
&lt;dependency&gt; &lt;dependency&gt;
@ -96,9 +96,9 @@
or above from the Hibernate website and add or above from the Hibernate website and add
<filename>hibernate-validator.jar</filename> and <filename>hibernate-validator.jar</filename> and
<filename>validation-api.jar</filename> in your classpath. Alternatively <filename>validation-api.jar</filename> in your classpath. Alternatively
add the following dependency in your add the following dependency in your <filename>pom.xml</filename>.</para>
<filename>pom.xml</filename>.</para>
<programlisting role="XML" language="XML">&lt;project&gt; <programlisting language="XML" role="XML">&lt;project&gt;
... ...
&lt;dependencies&gt; &lt;dependencies&gt;
&lt;dependency&gt; &lt;dependency&gt;
@ -117,7 +117,9 @@
<filename>hibernate-search.jar</filename> and <filename>hibernate-search.jar</filename> and
<filename>lucene-core-x.y.z.jar</filename> in your classpath. <filename>lucene-core-x.y.z.jar</filename> in your classpath.
Alternatively add the following dependency in your Alternatively add the following dependency in your
<filename>pom.xml</filename>.</para><programlisting role="XML" language="XML">&lt;project&gt; <filename>pom.xml</filename>.</para>
<programlisting language="XML" role="XML">&lt;project&gt;
... ...
&lt;dependencies&gt; &lt;dependencies&gt;
&lt;dependency&gt; &lt;dependency&gt;
@ -138,7 +140,8 @@
<classname>AnnotationConfiguration</classname> class instead of the <classname>AnnotationConfiguration</classname> class instead of the
<classname>Configuration</classname> class. Here is an example using the <classname>Configuration</classname> class. Here is an example using the
(legacy) <classname>HibernateUtil</classname> approach:</para> (legacy) <classname>HibernateUtil</classname> approach:</para>
<programlisting role="JAVA" language="JAVA">package hello;
<programlisting language="JAVA" role="JAVA">package hello;
import org.hibernate.*; import org.hibernate.*;
import org.hibernate.cfg.*; import org.hibernate.cfg.*;
@ -171,7 +174,7 @@ private static final SessionFactory sessionFactory;
<filename>hibernate.cfg.xml</filename>). Here is the equivalent of the <filename>hibernate.cfg.xml</filename>). Here is the equivalent of the
above declaration:</para> above declaration:</para>
<programlisting role="XML" language="XML">&lt;!DOCTYPE hibernate-configuration PUBLIC <programlisting language="XML" role="XML">&lt;!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN" "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt; "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
&lt;hibernate-configuration&gt; &lt;hibernate-configuration&gt;
@ -194,7 +197,8 @@ private static final SessionFactory sessionFactory;
<para>Alternatively, you can define the annotated classes and packages <para>Alternatively, you can define the annotated classes and packages
using the programmatic API</para> using the programmatic API</para>
<programlisting role="JAVA" language="JAVA">sessionFactory = new <emphasis role="bold">AnnotationConfiguration() <programlisting language="JAVA" role="JAVA">sessionFactory = new <emphasis
role="bold">AnnotationConfiguration()
.addPackage("test.animals") //the fully qualified package name .addPackage("test.animals") //the fully qualified package name
.addAnnotatedClass(Flight.class) .addAnnotatedClass(Flight.class)
.addAnnotatedClass(Sky.class) .addAnnotatedClass(Sky.class)
@ -321,4 +325,4 @@ private static final SessionFactory sessionFactory;
url="http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#configuration-logging">Logging</ulink> url="http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#configuration-logging">Logging</ulink>
in the Hibernate Core documentation.</para> in the Hibernate Core documentation.</para>
</section> </section>
</chapter> </chapter>

View File

@ -1,4 +1,4 @@
<?xml version='1.0' encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- <!--
~ Hibernate, Relational Persistence for Idiomatic Java ~ Hibernate, Relational Persistence for Idiomatic Java
~ ~
@ -22,8 +22,8 @@
~ 51 Franklin Street, Fifth Floor ~ 51 Franklin Street, Fifth Floor
~ Boston, MA 02110-1301 USA ~ Boston, MA 02110-1301 USA
--> -->
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"> "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<chapter id="xml-overriding"> <chapter id="xml-overriding">
<title>Overriding metadata through XML</title> <title>Overriding metadata through XML</title>
@ -44,7 +44,7 @@
the annotations one. So if you know the annotations structure, using the the annotations one. So if you know the annotations structure, using the
XML schema will be straightforward for you.</para> XML schema will be straightforward for you.</para>
<para>You can define one ot more XML files describing your metadata, these <para>You can define one or more XML files describing your metadata, these
files will be merged by the overriding engine.</para> files will be merged by the overriding engine.</para>
<section> <section>
@ -53,7 +53,7 @@
<para>You can define global level metadata available for all XML files. <para>You can define global level metadata available for all XML files.
You must not define these metadata more than once per deployment.</para> You must not define these metadata more than once per deployment.</para>
<programlisting role="XML" language="XML">&lt;?xml version="1.0" encoding="UTF-8"?&gt; <programlisting language="XML" role="XML">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;entity-mappings &lt;entity-mappings
xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns="http://java.sun.com/xml/ns/persistence/orm"
@ -347,7 +347,7 @@
<literal>mapped-superclass/attributes</literal> or <literal>mapped-superclass/attributes</literal> or
<literal>embeddable/attributes</literal>.</para> <literal>embeddable/attributes</literal>.</para>
<programlisting role="XML" language="XML"> &lt;attributes&gt; <programlisting language="XML" role="XML"> &lt;attributes&gt;
&lt;id name="id"&gt; &lt;id name="id"&gt;
&lt;column name="fld_id"/&gt; &lt;column name="fld_id"/&gt;
&lt;generated-value generator="generator" strategy="SEQUENCE"/&gt; &lt;generated-value generator="generator" strategy="SEQUENCE"/&gt;
@ -388,7 +388,7 @@
<literal>mapped-superclass/attributes</literal> or <literal>mapped-superclass/attributes</literal> or
<literal>embeddable/attributes</literal>.</para> <literal>embeddable/attributes</literal>.</para>
<programlisting role="XML" language="XML"> &lt;attributes&gt; <programlisting language="XML" role="XML"> &lt;attributes&gt;
&lt;one-to-many name="players" fetch="EAGER"&gt; &lt;one-to-many name="players" fetch="EAGER"&gt;
&lt;map-key name="name"/&gt; &lt;map-key name="name"/&gt;
&lt;join-column name="driver"/&gt; &lt;join-column name="driver"/&gt;
@ -424,4 +424,4 @@
informations in the chapter describing annotations.</para> informations in the chapter describing annotations.</para>
</section> </section>
</section> </section>
</chapter> </chapter>