From hibernate-commits at lists.jboss.org Wed May 26 12:18:28 2010 Content-Type: multipart/mixed; boundary="===============4165705447726162003==" MIME-Version: 1.0 From: hibernate-commits at lists.jboss.org To: hibernate-commits at lists.jboss.org Subject: [hibernate-commits] Hibernate SVN: r19615 - core/trunk/documentation/manual/src/main/docbook/en-US/content. Date: Wed, 26 May 2010 12:18:28 -0400 Message-ID: <201005261618.o4QGISwj022430@svn01.web.mwc.hst.phx2.redhat.com> --===============4165705447726162003== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: epbernard Date: 2010-05-26 12:18:28 -0400 (Wed, 26 May 2010) New Revision: 19615 Modified: core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_map= ping.xml Log: HHH-5149 Merge @Any documentation Modified: core/trunk/documentation/manual/src/main/docbook/en-US/content/ba= sic_mapping.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_ma= pping.xml 2010-05-26 16:17:33 UTC (rev 19614) +++ core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_ma= pping.xml 2010-05-26 16:18:28 UTC (rev 19615) @@ -4747,21 +4747,62 @@ Any = There is one more type of property mapping. The - <any> mapping element defines a polymorphic - association to classes from multiple tables. This type of mapping - requires more than one column. The first column contains the type of= the - associated entity. The remaining columns contain the identifier. It = is - impossible to specify a foreign key constraint for this kind of - association. This is not the usual way of mapping polymorphic - associations and you should use this only in special cases. For exam= ple, - for audit logs, user session data, etc. + @Any mapping defines a polymorphic associatio= n to + classes from multiple tables. This type of mapping requires more than + one column. The first column contains the type of the associated ent= ity. + The remaining columns contain the identifier. It is impossible to + specify a foreign key constraint for this kind of association. This = is + not the usual way of mapping polymorphic associations and you should= use + this only in special cases. For example, for audit logs, user session + data, etc. = - The meta-type attribute allows the applicat= ion - to specify a custom type that maps database column values to persist= ent - classes that have identifier properties of the type specified by - id-type. You must specify the mapping from values= of - the meta-type to class names. + The @Any annotation describes the column + holding the metadata information. To link the value of the metadata + information and an actual entity type, The + @AnyDef and @AnyDefs + annotations are used. The metaType attribute allo= ws + the application to specify a custom type that maps database column + values to persistent classes that have identifier properties of the = type + specified by idType. You must specify the mapping + from values of the metaType to class names. = + @Any( metaColumn =3D= @Column( name =3D "property_type" ), fetch=3DFetchType.EAGER ) +(a)AnyMetaDef( = + idType =3D "integer", = + metaType =3D "string", = + metaValues =3D { + @MetaValue( value =3D "S", targetEntity =3D StringProperty.class ), + @MetaValue( value =3D "I", targetEntity =3D IntegerProperty.class ) + } ) +(a)JoinColumn( name =3D "property_id" ) +public Property getMainProperty() { + return mainProperty; +} + + Note that @AnyDef can be mutualized and + reused. It is recommended to place it as a package metadata in this + case. + + //on a package +(a)AnyMetaDef( name=3D"property" = + idType =3D "integer", = + metaType =3D "string", = + metaValues =3D { + @MetaValue( value =3D "S", targetEntity =3D StringProperty.class ), + @MetaValue( value =3D "I", targetEntity =3D IntegerProperty.class ) + } ) +package org.hibernate.test.annotations.any; + + +//in a class + @Any( metaDef=3D"property", metaColumn =3D @Column( name =3D "property= _type" ), fetch=3DFetchType.EAGER ) + @JoinColumn( name =3D "property_id" ) + public Property getMainProperty() { + return mainProperty; + } + + The hbm.xml equivalent is: + <any name=3D"being" id-type=3D"long"= meta-type=3D"string"> <meta-value value=3D"TBL_ANIMAL" class=3D"Animal"/> <meta-value value=3D"TBL_HUMAN" class=3D"Human"/> @@ -4770,6 +4811,11 @@ <column name=3D"id"/> </any> = + + You cannot mutualize the metadata in hbm.xml as you can in + annotations. + + --===============4165705447726162003==--