I'm sorry to be such a beginner, but I hope you can answer this for me.
I have a HashMap and the keys will all be strings, but the values will be different types of objects (String, Date, List).
How do I map this?
I tried:
Code:
<hibernate-mapping>
<class name="collective.asset.NewAsset" table="NEWASSET" discriminator-value="X">
<id name="id" unsaved-value="any">
<generator class="native" />
</id>
<discriminator column="assetSubclass" />
<many-to-one name="assetType" class="collective.asset.AssetType" column="assetTypeId" />
<map name="metadata" table="NEWMETADATA">
<key column="assetId"/>
<index column="metadataFieldLabel" type="string"/>
<many-to-many class="collective.asset.AbstractMetadataValue" column="valueId" />
</map>
<subclass name="collective.mb.template.Template" discriminator-value="T" lazy="true" >
<property name="previewFile"/>
<property name="fileName"/>
<list name="pdfBlocks" table="TemplatePdfBlocks">
<key column="parent"/>
<index column="idx"/>
<many-to-many class="collective.mb.blocks.AbstractBlock" column="blockId" />
</list>
</subclass>
</class>
</hibernate-mapping>
and have classes extending AbstractMetadataValue such as:
Code:
public class DateMetadataValue extends AbstractMetadataValue
{
private Date value;
public DateMetadataValue()
{
}
public DateMetadataValue(Date date)
{
value = date;
}
public Date getValue()
{
return value;
}
public void setValue(Date date)
{
value = date;
}
}
However when I do a search:
select asset1 from NewAsset as asset1 where asset1.metadata['key'].value = 'value'
I get an error that the value property doesn't exist. This is because it is treating the object pulled by asset1.metadata['key'] as a collective.asset.AbstractMetadataValue object, which doesn't have a value property.
Problem with current solution:
I don't know how to write the correct mapping file such that it uses the discriminator so it knows what type of object to call getValue() on.
Problem with alternate solution (having a value property in AbstractMetadataValue):
I don't know how to map to java.lang.Object.