-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Mapping a map
PostPosted: Fri Mar 05, 2004 5:41 pm 
Newbie

Joined: Wed Nov 12, 2003 3:45 pm
Posts: 8
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.