From: <one...@us...> - 2003-05-01 07:53:28
|
Update of /cvsroot/hibernate/Hibernate2/doc/reference/src In directory sc8-pr-cvs1:/tmp/cvs-serv729/doc/reference/src Modified Files: manipulating_data.xml Log Message: doco for metadata API Index: manipulating_data.xml =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/doc/reference/src/manipulating_data.xml,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** manipulating_data.xml 26 Apr 2003 03:58:29 -0000 1.9 --- manipulating_data.xml 1 May 2003 07:53:20 -0000 1.10 *************** *** 1119,1124 **** </sect1> ! <sect1 id="manipulating-data-s16"> <title>Frequently Asked Questions</title> --- 1119,1157 ---- </sect1> ! <sect1 id="manipulating-data-s16"> + <title>Metadata API</title> + <para> + Hibernate requires a very rich meta-level model of all entity and value types. From time + to time, this model is very useful to the application itself. For example, the application + might use Hibernate's metadata to implement a "smart" deep-copy algorithm that understands + which objects should be copied (eg. mutable value types) and which should not (eg. + immutable value types and, possibly, associated entities). + </para> + <para> + Hibernate exposes metadata via the <literal>ClassMetadata</literal> and + <literal>CollectionMetadata</literal> interfaces and the <literal>Type</literal> + hierarchy. Instances of the metadata interfaces may be obtained from the + <literal>SessionFactory</literal>. + </para> + + <programlisting><![CDATA[Cat fritz = ......; + Long id = (Long) catMeta.getIdentifier(fritz); + ClassMetadata catMeta = sessionfactory.getClassMetadata(Cat.class); + Object[] propertyValues = catMeta.getPropertyValues(fritz); + String[] propertyNames = catMeta.getPropertyNames(); + Type[] propertyTypes = catMeta.getPropertyTypes(); + // get a Map of all properties which are not collections or associations + // TODO: what about components? + Map namedValues = new HashMap(); + for ( int i=0; i<propertyNames.length; i++ ) { + if ( !propertyTypes[i].isEntityType() && !propertyTypes[i].isCollectionType() ) { + namedValues.put( propertyNames[i], propertyValues[i] ); + } + }]]></programlisting> + + </sect1> + + <sect1 id="manipulating-data-s17"> <title>Frequently Asked Questions</title> |