I would like to read gladly by this interface ClassMetadata the data from a database. However I can only read data of simple PropertyTyp by the method ClassMetadata.getPropertyValue(Object obj, propertyName) and I cannot read data of CollectionTyp.
Please if someone know how to read data of CollectionTyp by the interface ClassMetadata please writes some solutions.
This is my Mapping name: Category
and a Category has a set of items
<hibernate-mapping package="dms.business">
<class
name="Category"
table="category"
proxy="Category"
>
<id
name="id"
type="integer"
column="id"
>
<generator class="native"/>
</id>
<property
name="description"
column="description"
type="string"
not-null="false"
length="100"
/>
<property
name="name"
column="name"
type="string"
not-null="true"
length="50"
/>
<set
cascade="delete-orphan"
name="items"
table="link_category_item"
inverse="true"
lazy="true"
>
<key column="category_id" />
<one-to-many class="Item" />
</set>
</class>
</hibernate-mapping>
This is the Methode to read the data
public void createRow(Object dao,String names[], ClassMetadata metadata) throws HibernateException
{
for(int j = 0; j < names.length; j++)
{
if(!metadata.getPropertyType(names[j]).isPersistentCollectionType())
{
System.out.println(metadata.getPropertyValue(dao,names[j]));
}
else
{
// How to read PersistentCollection ?
}
}
}
|