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.