-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problems using entity-name
PostPosted: Wed Sep 03, 2008 7:56 am 
Newbie

Joined: Wed Sep 03, 2008 7:37 am
Posts: 2
Hi. I´m using Hibernate Core 3.2.4 and have some problems using the attribute entity-name in mapping-file. I use that because I want to persist different instances of class Properties in different tables.

I have a class Document and another one called Properties:


Code:
public class Document {

         .....
   
   public Properties[] getProperties() {
      return _Properties;
   }

   public void setProperties(Properties[] docprops) {
      this._Properties = docprops;
   }
        ........
}

public class Properties {
   
        .....
   
   public void setName(String name) {
      _Name = name;
   }

   public String getValue() {
      return _Value;
   }

   public void setValue(String value) {
      _Value = value;
   }
}



I made the following mapping:



Code:
<hibernate-mapping package="de.test">
  <class name="Document">
    <id name="FileName"></id>
    <array name="Properties" cascade="all">
      <key column="Props"></key>
      <list-index column="nr"></list-index>
      <one-to-many entity-name="Test"  class="Properties"></one-to-many>
    </array>
  </class>
  <class entity-name="Test"  name="Properties">
    <id column="id" type="long">
      <generator class="native"></generator>
    </id>
    <property name="Name"/>
    <property name="Value"></property>
  </class>
</hibernate-mapping>


That ends in following exception:

java.lang.IllegalArgumentException: array element type mismatch
at java.lang.reflect.Array.set(Native Method)
at org.hibernate.collection.PersistentArrayHolder.getSnapshot(PersistentArrayHolder.java:50)
at org.hibernate.engine.CollectionEntry.<init>(CollectionEntry.java:68)
at org.hibernate.engine.StatefulPersistenceContext.addCollection(StatefulPersistenceContext.java:695)
at org.hibernate.engine.StatefulPersistenceContext.addNewCollection(StatefulPersistenceContext.java:670)
at org.hibernate.event.def.WrapVisitor.processArrayOrNewCollection(WrapVisitor.java:77)
at org.hibernate.event.def.WrapVisitor.processCollection(WrapVisitor.java:51)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:101)
at org.hibernate.event.def.WrapVisitor.processValue(WrapVisitor.java:98)
at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:55)
at org.hibernate.event.def.AbstractSaveEventListener.visitCollectionsBeforeSave(AbstractSaveEventListener.java:360)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:269)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:180)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
at $Proxy0.persist(Unknown Source)
at de.test.Tester.execute(Tester.java:45)
at de.test.Tester.main(Tester.java:19)


All works fine when not using the attribute entity-name. But then all Properties-Instances will be persisted in one table. It seems to me, that when using the entity-name attribute hibernate not knows that the underlying class belongs to class properties. What can I do?

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2008 9:58 am 
Newbie

Joined: Wed Sep 03, 2008 7:37 am
Posts: 2
Now I solved the problem. I just have to add the following into the "array" - element: "element-class="de.test.Properties"

Unbelievable - I needed two days to find that out....... sorry for asking the forum for some simple thing like that.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.