-->
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.  [ 3 posts ] 
Author Message
 Post subject: MapAccessor throws ClassCastException
PostPosted: Fri Feb 29, 2008 7:44 am 
Newbie

Joined: Tue Feb 26, 2008 11:33 am
Posts: 7
Hello,

I have a problem with entities in entity-mode dynamic-map.

For a legacy database I have to use maps for dynamic entities. So I use entity-mode dynamic-map. Also a table has a foreign-key to a non-primary-key of an other table.

I played with the mapping: loading existing entries and changing them now works good. But if I try to persist a new filled map I get an exception, which I don't understand.

I would be very happy if someone could tell me, what I do wrong.

My mapping looks like this:
Code:
<class entity-name="A" table="TABLE_A">

  <id name="A_ID" type="long">
    <generator class="sequence">
      <param name="sequence">TABLE_A_SEQ</param>
    </generator>
  </id>

  <property name="A_SECOND_ID" type="integer" not-null="true" />

  <properties name="ATTRIBUTESKEY" update="false" unique="true">
    <property name="A_ID" column="A_ID" type="long" update="false" insert="false" />
    <property name="A_SECOND_ID" type="integer" update="false" insert="false" />
  </properties>
       
  <property name="A_STATUS" type="string" />

  <map name="ATTRIBUTES" cascade="all" lazy="false">
    <key property-ref="ATTRIBUTESKEY" not-null="true" unique="true" update="false">
      <column name="ATTRIBUTE_A_ID" />
      <column name="ATTRIBUTE_SECOND_ID" />
    </key>
    <map-key column="ATTRIBUTE_NAME" type="string" />
    <one-to-many entity-name="ATTRIBUTE" />
  </map>
       
</class>

<class entity-name="ATTRIBUTE" table="TABLE_ATTRIBUTE" lazy="false">
  <id name="ATTRIBUTE_ID" type="long">
    <generator class="sequence">
      <param name="sequence">TABLE_ATTRIBUTE_SEQ</param>
    </generator>
  </id>

  <property name="ATTRIBUTE_SECOND_ID" type="integer" insert="false" update="false"/>
  <property name="ATTRIBUTE_NAME" type="string" insert="false" update="false" />

  <property name="ATTRIBUTE_STRING" type="string" />
</class>


My test-code to persist a new A-entity:
Code:
[...]
Map a = new HashMap();

a.put("A_SECOND_ID", 1);
a.put("A_STATUS", "1");
     
// why do I have to do this?
a.put("ATTRIBUTESKEY", a);

session.persist("A", a);
     
Map attributes = new HashMap();
a.put("ATTRIBUTES", attributes);
     
Map attribute = new HashMap();
attribute.put("ATTRIBUTE_STRWERT", "value");
attribute.put("ATTRIBUTE_NAME", "test");
     
attributes.put("test", attribute);

tx.commit();

[...]


the thrown exception:
Code:
java.lang.ClassCastException: java.lang.Long
   at org.hibernate.property.MapAccessor$MapGetter.get(MapAccessor.java:67)
   at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValue(AbstractComponentTuplizer.java:64)
   at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValues(AbstractComponentTuplizer.java:70)
   at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:353)
   at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:348)
   at org.hibernate.engine.ForeignKeys$Nullifier.nullifyTransientReferences(ForeignKeys.java:77)
   at org.hibernate.engine.ForeignKeys$Nullifier.nullifyTransientReferences(ForeignKeys.java:47)
   at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:288)
   at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
   at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:94)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
   at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:507)
   at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:499)
   at org.hibernate.engine.CascadingAction$5.cascade(CascadingAction.java:218)
   at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
   at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
   at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
   at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:296)
   at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:242)
   at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:219)
   at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
   at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
   at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:131)
   at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:122)
   at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)


Greetings,
Mark


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 04, 2008 7:27 am 
Newbie

Joined: Tue Feb 26, 2008 11:33 am
Posts: 7
Hello all,

*push* ;)

Could someone please tell me, where is the mistake? Is it a hibernate-bug or am I using it wrong?

greetings
Mark


Top
 Profile  
 
 Post subject: Bug with key and property groups?
PostPosted: Thu Jun 19, 2008 6:33 pm 
Newbie

Joined: Fri May 23, 2008 11:12 am
Posts: 8
I just had a similar problem. I found that the key column appears to die a horrible death when referencing a property specified by "properties". Once I took "A_ID" out of a properties group it worked like a charm but of course broke something else. My set looked something like the following. I ended up debugging the hibernate code and found that it was passing an Attachment object into the query was assuming it was an IntegerType. Is this a bug?

<set name="attachments" inverse="true">
<key column="theId" property-ref="ATTRIBUTESKEY.A_ID" ></key>
<one-to-many entity-name="Attachment" />
</set>


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

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.