HHH-4933 Write documentation on composite identity, partial generated value and derived identity

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18860 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Emmanuel Bernard 2010-02-23 19:12:49 +00:00
parent 170f7b273e
commit cd3db638aa
5 changed files with 651 additions and 377 deletions

File diff suppressed because it is too large Load Diff

View File

@ -204,7 +204,7 @@ private static final SessionFactory sessionFactory;
annotations, except for this startup routine change or in the annotations, except for this startup routine change or in the
configuration file. You can use your favorite configuration method for configuration file. You can use your favorite configuration method for
other properties ( <filename>hibernate.properties</filename>, other properties ( <filename>hibernate.properties</filename>,
<filename>hibernate.cfg.xml</filename>, programmatic APIs, etc). </para> <filename>hibernate.cfg.xml</filename>, programmatic APIs, etc).</para>
<note> <note>
<para>You can mix annotated persistent classes and classic <para>You can mix annotated persistent classes and classic
@ -225,7 +225,7 @@ private static final SessionFactory sessionFactory;
conflict occurs.</para> conflict occurs.</para>
</section> </section>
<section> <section id="ann-setup-properties">
<title id="setup-properties">Properties</title> <title id="setup-properties">Properties</title>
<para>On top of the Hibernate Core properties, Hibernate Annotations <para>On top of the Hibernate Core properties, Hibernate Annotations

View File

@ -0,0 +1,38 @@
package org.hibernate.test.annotations.derivedidentities.e5.c;
import org.hibernate.Session;
import org.hibernate.test.annotations.TestCase;
import org.hibernate.test.util.SchemaUtil;
/**
* @author Emmanuel Bernard
*/
public class ForeignGeneratorViaMapsIdTest extends TestCase {
public void testForeignGenerator() throws Exception {
assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "patient_id", getCfg() ) );
Person e = new Person();
Session s = openSession( );
s.getTransaction().begin();
s.persist( e );
MedicalHistory d = new MedicalHistory();
d.patient = e;
s.persist( d );
s.flush();
s.clear();
d = (MedicalHistory) s.get( MedicalHistory.class, e.id);
assertEquals( e.id, d.id );
s.delete( d );
s.delete( d.patient );
s.getTransaction().rollback();
s.close();
}
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
MedicalHistory.class,
Person.class
};
}
}

View File

@ -0,0 +1,25 @@
package org.hibernate.test.annotations.derivedidentities.e5.c;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.MapsId;
import javax.persistence.OneToOne;
/**
* @author Emmanuel Bernard
*/
@Entity
public class MedicalHistory implements Serializable {
@Id
Integer id;
@MapsId
@JoinColumn(name = "patient_id")
@OneToOne
Person patient;
}

View File

@ -0,0 +1,14 @@
package org.hibernate.test.annotations.derivedidentities.e5.c;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
/**
* @author Emmanuel Bernard
*/
@Entity
public class Person {
@Id @GeneratedValue
Integer id;
}