There is something wrong in my mapping file, but I have no idea what it is...
I want to use a HashMap to store key-value Strings and get a org.hibernate.PropertyAccessException
I set hibernate.cglib.use_reflection_optimizer=false
Hibernate version:3.1
Mapping documents:
...
<map name="attributes">
<key column="litData_id" not-null="true"/>
<map-key column="key" type="string"/>
<element column="value" type="string"/>
</map>
...
POJO Class
...
private java.util.HashMap<String, String> attributes;
public java.util.HashMap<String, String> getAttributes() {
return attributes;
}
public void setAttributes(java.util.HashMap<String, String> attributes) {
this.attributes = attributes;
}
...
I changed the set method, just to see what is going on to :
public void setAttributes(Object attributes) {
if (attributes instanceof HashMap) {
this.attributes = (HashMap) attributes;
}else if (attributes instanceof PersistentMap) {
logger.warn("wrong type");
}
}
no exception occurs, but clearly the HasMap is not initialized from the database
Full stack trace of any exception that occurs:
ERROR org.hibernate.property.BasicPropertyAccessor - IllegalArgumentException in class: org.lito.core.LitData, setter method of property: attributes
4026 [main] ERROR org.hibernate.property.BasicPropertyAccessor - expected type: java.util.HashMap, actual value: org.hibernate.collection.PersistentMap
Exception in thread "main" org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of org.lito.core.LitData.attributes
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:104)
at org.hibernate.tuple.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:330)
at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:188)
at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3232)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:253)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:167)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:101)
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:623)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:599)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:603)
at org.lito.hibenate.DataManager.createAndSaveLitData(DataManager.java:150)
at org.util.test.InitDB.testData(InitDB.java:68)
at org.util.test.InitDB.main(InitDB.java:182)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:42)
... 15 more
I hope someone can help me, I'm really feeling lost with this problem.
Thank you
Maja
|