-->
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: Problem using HashMap: PropertyAccessException
PostPosted: Fri Dec 16, 2005 8:21 am 
Newbie

Joined: Fri Dec 16, 2005 6:45 am
Posts: 1
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


Top
 Profile  
 
 Post subject: Re: Problem using HashMap: PropertyAccessException
PostPosted: Sat Dec 17, 2005 1:49 pm 
Beginner
Beginner

Joined: Sat Dec 17, 2005 1:24 pm
Posts: 42
Location: Berlin, Germany
Hi!

I have very much the same mapping in one of my applications and this works without a problem. However, I remember that I got several of these exceptions myself when I started with Hibernate. Unfortunately, I am not sure what I did to solve the problem.

However, two things that are different in my code:

1. I use an Interface to access the map instead of the HashMap object directly:

...
private Map<Long,String> attributes;
...

2. and I initialize attributes in the constructor:

public POJOClassConstructor() {
attributes = new HashMap<String,String>();
}

Does that change anything?

All the best,

René


Top
 Profile  
 
 Post subject: Re: Problem using HashMap: PropertyAccessException
PostPosted: Wed Feb 16, 2011 5:21 pm 
Newbie

Joined: Tue Feb 01, 2011 8:17 pm
Posts: 7
Thanks a lot ReneStolp.

You are suppose to use the interface and not the implementation. It solve also my problem with the list and ArrayList :-)


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.