HHH-5149 remove alternative mapping section
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@19620 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
89b2659331
commit
c906bc9780
|
@ -5396,181 +5396,6 @@ package org.hibernate.test.annotations.any;
|
|||
</class></programlisting>
|
||||
</section>
|
||||
|
||||
<section id="mapping-alternatives">
|
||||
<title>Metadata alternatives</title>
|
||||
|
||||
<para>XML does not suit all users so there are some alternative ways to
|
||||
define O/R mapping metadata in Hibernate.</para>
|
||||
|
||||
<section id="mapping-xdoclet">
|
||||
<title>Using XDoclet markup</title>
|
||||
|
||||
<para>Many Hibernate users prefer to embed mapping information directly
|
||||
in sourcecode using XDoclet <literal>@hibernate.tags</literal>. We do
|
||||
not cover this approach in this reference guide since it is considered
|
||||
part of XDoclet. However, we include the following example of the
|
||||
<literal>Cat</literal> class with XDoclet mappings:</para>
|
||||
|
||||
<programlisting role="JAVA">package eg;
|
||||
import java.util.Set;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @hibernate.class
|
||||
* table="CATS"
|
||||
*/
|
||||
public class Cat {
|
||||
private Long id; // identifier
|
||||
private Date birthdate;
|
||||
private Cat mother;
|
||||
private Set kittens
|
||||
private Color color;
|
||||
private char sex;
|
||||
private float weight;
|
||||
|
||||
/*
|
||||
* @hibernate.id
|
||||
* generator-class="native"
|
||||
* column="CAT_ID"
|
||||
*/
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
private void setId(Long id) {
|
||||
this.id=id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @hibernate.many-to-one
|
||||
* column="PARENT_ID"
|
||||
*/
|
||||
public Cat getMother() {
|
||||
return mother;
|
||||
}
|
||||
void setMother(Cat mother) {
|
||||
this.mother = mother;
|
||||
}
|
||||
|
||||
/**
|
||||
* @hibernate.property
|
||||
* column="BIRTH_DATE"
|
||||
*/
|
||||
public Date getBirthdate() {
|
||||
return birthdate;
|
||||
}
|
||||
void setBirthdate(Date date) {
|
||||
birthdate = date;
|
||||
}
|
||||
/**
|
||||
* @hibernate.property
|
||||
* column="WEIGHT"
|
||||
*/
|
||||
public float getWeight() {
|
||||
return weight;
|
||||
}
|
||||
void setWeight(float weight) {
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
/**
|
||||
* @hibernate.property
|
||||
* column="COLOR"
|
||||
* not-null="true"
|
||||
*/
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
void setColor(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
/**
|
||||
* @hibernate.set
|
||||
* inverse="true"
|
||||
* order-by="BIRTH_DATE"
|
||||
* @hibernate.collection-key
|
||||
* column="PARENT_ID"
|
||||
* @hibernate.collection-one-to-many
|
||||
*/
|
||||
public Set getKittens() {
|
||||
return kittens;
|
||||
}
|
||||
void setKittens(Set kittens) {
|
||||
this.kittens = kittens;
|
||||
}
|
||||
// addKitten not needed by Hibernate
|
||||
public void addKitten(Cat kitten) {
|
||||
kittens.add(kitten);
|
||||
}
|
||||
|
||||
/**
|
||||
* @hibernate.property
|
||||
* column="SEX"
|
||||
* not-null="true"
|
||||
* update="false"
|
||||
*/
|
||||
public char getSex() {
|
||||
return sex;
|
||||
}
|
||||
void setSex(char sex) {
|
||||
this.sex=sex;
|
||||
}
|
||||
}</programlisting>
|
||||
|
||||
<para>See the Hibernate website for more examples of XDoclet and
|
||||
Hibernate.</para>
|
||||
</section>
|
||||
|
||||
<section id="mapping-annotations" revision="2">
|
||||
<title>Using JDK 5.0 Annotations</title>
|
||||
|
||||
<para>JDK 5.0 introduced XDoclet-style annotations at the language level
|
||||
that are type-safe and checked at compile time. This mechanism is more
|
||||
powerful than XDoclet annotations and better supported by tools and
|
||||
IDEs. IntelliJ IDEA, for example, supports auto-completion and syntax
|
||||
highlighting of JDK 5.0 annotations. The new revision of the EJB
|
||||
specification (JSR-220) uses JDK 5.0 annotations as the primary metadata
|
||||
mechanism for entity beans. Hibernate3 implements the
|
||||
<literal>EntityManager</literal> of JSR-220 (the persistence API).
|
||||
Support for mapping metadata is available via the <emphasis>Hibernate
|
||||
Annotations</emphasis> package as a separate download. Both EJB3
|
||||
(JSR-220) and Hibernate3 metadata is supported.</para>
|
||||
|
||||
<para>This is an example of a POJO class annotated as an EJB entity
|
||||
bean:</para>
|
||||
|
||||
<programlisting role="JAVA">@Entity(access = AccessType.FIELD)
|
||||
public class Customer implements Serializable {
|
||||
|
||||
@Id;
|
||||
Long id;
|
||||
|
||||
String firstName;
|
||||
String lastName;
|
||||
Date birthday;
|
||||
|
||||
@Transient
|
||||
Integer age;
|
||||
|
||||
@Embedded
|
||||
private Address homeAddress;
|
||||
|
||||
@OneToMany(cascade=CascadeType.ALL)
|
||||
@JoinColumn(name="CUSTOMER_ID")
|
||||
Set<Order> orders;
|
||||
|
||||
// Getter/setter and business methods
|
||||
}</programlisting>
|
||||
|
||||
<note>
|
||||
<title>Note</title>
|
||||
|
||||
<para>Support for JDK 5.0 Annotations (and JSR-220) is currently under
|
||||
development. Please refer to the Hibernate Annotations module for more
|
||||
details.</para>
|
||||
</note>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<section id="mapping-generated" revision="1">
|
||||
<title>Generated properties</title>
|
||||
|
||||
|
|
Loading…
Reference in New Issue