-->
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 with a List element
PostPosted: Wed Sep 01, 2010 7:49 pm 
Newbie

Joined: Wed Sep 01, 2010 7:33 pm
Posts: 1
I am trying to map the following object but when I try and merge I get a classCastException because it tries to find the identifier on the list not the element of the list. Any suggestions would be appreciated.

Code:
public class Object1{
    Long oid;
    String x;
    Map<String, List<Object2>> data;

    //appropriate getters and setters.
}

public class Object2{
    Long oid;
    String y;
    String z;

    //appropriate getters and setters.

}

Tried to map the map using:

<class  name="Object1"
            table="OBJECT1"
            dynamic-update="true"
            schema="model"
            >
        <id
                name="OID"
                type="java.lang.Long"
                column="OID">
            <generator class="IDGenerator"/>
        </id>

        <property name="x"
                  column="X"
                  type="java.lang.String"/>



    <map name="data" table="DATA" >
        <key column="DATA_OID"/>
        <map-key type="java.lang.String" column="KEY"/>
        <many-to-many class="Object2"/>
    </map>
</class>

<class  name="Object2"
            table="OBJECT2"
            dynamic-update="true"
            schema="model"
            >
       
        <id
                name="oid"
                type="java.lang.Long"
                column="OID">
            <generator class="IDGenerator"/>
        </id>
        <property name="y"
                  column="Y"
                  type="java.lang.String"/>

        <property name="z"
                  column="Z">
            <type name="java.lang.String"/>
        </property>       
    </class>


Exception I currently see when trying to merge:

Caused by: org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter o
f minestar.platform.persistence.AbstractPersistentComponent.OID
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:1
71)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.ja
va:183)
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersis
ter.java:3596)
at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersiste
r.java:3312)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:181)
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:218)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:397)
at org.hibernate.type.EntityType.replace(EntityType.java:253)
at org.hibernate.type.MapType.replaceElements(MapType.java:74)
at org.hibernate.type.CollectionType.replace(CollectionType.java:552)
at org.hibernate.type.AbstractType.replace(AbstractType.java:153)
at org.hibernate.type.TypeFactory.replaceAssociations(TypeFactory.java:564)
at org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.ja
va:366)
at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventList
ener.java:195)
at org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener.entityIsTrans
ient(IdTransferringMergeEventListener.java:58)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:
123)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:
53)
at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:677)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:661)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:665)

... 104 more
Caused by: java.lang.IllegalArgumentException: java.lang.ClassCastException@c4eeea
at sun.reflect.GeneratedMethodAccessor20.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:1
45)
... 127 more


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.