Hello,
it seems I am affected of Issue 1427982, so I give
2.1.1 a try.
My first Testresult:
net.sf.dozer.util.mapping.MappingException:
java.lang.IllegalArgumentException: Duplicate Class
Mapping Found. Source: SiO_EdelmetallImpl Destination:
OEdelmetall
Extract of BeanMapping.xml
<mapping type="one-way"
bean-factory="de.subito.transfer.project.sms.common.services.ExportBeanFactory">
<class-a>OEdelmetall</class-a>
<class-b>SiO_EdelmetallImpl</class-b>
</mapping>
<mapping type="one-way"
bean-factory="de.subito.transfer.project.sms.common.services.ImportBeanFactory">
<class-a>SiO_EdelmetallImpl</class-a>
<class-b>OEdelmetall</class-b>
</mapping>
<mapping type="one-way"
bean-factory="de.subito.transfer.project.sms.common.services.ExportBeanFactory">
<class-a>OEdelmetall</class-a>
<class-b>SMSSicherungsobjektImpl</class-b>
</mapping>
<mapping type="one-way"
bean-factory="de.subito.transfer.project.sms.common.services.ImportBeanFactory">
<class-a>SMSSicherungsobjektImpl</class-a>
<class-b>OEdelmetall</class-b>
</mapping>
Declaration of Classes
public class SiO_EdelmetallImpl extends
SMSSicherungsobjektImpl implements SiO_Edelmetall
public class SMSSicherungsobjektImpl extends
TransformHelperImpl implements SMSSicherungsobjekt
public class TransformHelperImpl implements TransformHelper
public class OEdelmetall extends OMobilie implements
java.io.Serializable
public class OMobilie extends Objekt
public class Objekt implements java.io.Serializable
Because Version 2.0.1 works fine at this point and im
not seeing a duplication I think it is a error.
If not, please give me some hint for solving my problem.
Thanks.
Matthias
Logged In: YES
user_id=550744
Issue 1427982 was taken out for 2.1.1. I thought it was a
severe performance hit...but after studying it some more I
think I will put it back into the 2.1.2 release this week.
The bug fix was to add to BruteForcePropertyDescriptor.java was:
protected Method getReadMethod(Class bean) {
if (readMethod == null ||
!readMethod.getDeclaringClass().isAssignableFrom(bean)) {
vs.
protected Method getReadMethod(Class bean) {
if (readMethod == null) {
This should also be done for public Method getWriteMethod() {.
Now...your duplicate class mapping does look like a bug. We
create maps bi-directionally...so the class map key was
added bi-directionally for your one way map. This will be
fixed for 2.1.2 released this week.
Thanks for the help!
Franz
Logged In: YES
user_id=1368792
With Dozer 2.2 I got
MapId: null
Type: bi-directional
Source parent class: SicherheitK
Source field name: smsID
Source field type: generic
Source field value: null
Dest parent class: Si_GrundpfandrechtImpl
Dest field name: ID
Dest field type: java.lang.Integer
net.sf.dozer.util.mapping.MappingException:
java.lang.IllegalArgumentException: object is not an
instance of declaring class
at
net.sf.dozer.util.mapping.propertydescriptor.BruteForcePropertyDescriptor.getPropertyValue(BruteForcePropertyDescriptor.java:112)
at
net.sf.dozer.util.mapping.fieldmap.FieldMap.getSrcFieldValue(FieldMap.java:109)
at
net.sf.dozer.util.mapping.MappingProcessor.mapField(MappingProcessor.java:258)
at
net.sf.dozer.util.mapping.MappingProcessor.map(MappingProcessor.java:242)
at
net.sf.dozer.util.mapping.MappingProcessor.processSuperTypeMapping(MappingProcessor.java:1073)
at
net.sf.dozer.util.mapping.MappingProcessor.map(MappingProcessor.java:233)
at
net.sf.dozer.util.mapping.MappingProcessor.map(MappingProcessor.java:157)
at
net.sf.dozer.util.mapping.MappingProcessor.map(MappingProcessor.java:140)
at
net.sf.dozer.util.mapping.DozerBeanMapper.map(DozerBeanMapper.java:104)
Caused by: java.lang.IllegalArgumentException: object is not
an instance of declaring class
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:324)
at
net.sf.dozer.util.mapping.propertydescriptor.BruteForcePropertyDescriptor.getPropertyValue(BruteForcePropertyDescriptor.java:102)
... 66 more
Declaration of Classes
SicherheitK
public void setSmsID(String smsID)
public String getSmsID()
public class Si_GrundpfandrechtImpl extends
Si_PfandrechtImpl implements Si_Grundpfandrecht
public class Si_PfandrechtImpl extends SMSSicherheitImpl
implements Si_Pfandrecht
public class SMSSicherheitImpl implements SMSSicherheit
private Integer m_ID;
public Integer getID()
public void setID(Integer p_ID)
Extract of BeanMapping.xml
<mapping type="one-way"
bean-factory="de.subito.transfer.project.sms.common.services.ExportBeanFactory">
<class-a>de.subito.transfer.project.sms.common.domain.model.SicherheitKrebis</class-a>
<class-b>de.subito.transfer.project.sms.common.domain.fitbean.Si_GrundpfandrechtImpl</class-b>
</mapping>
<mapping type="one-way" bean-factory="ExportBeanFactory">
<class-a>SicherheitK</class-a>
<class-b>SMSSicherheitImpl</class-b>
<field>
<a>smsID</a>
<b>ID</b>
</field>
</mapping>
<mapping type="one-way" bean-factory="ImportBeanFactory">
<class-a>SMSSicherheitImpl</class-a>
<class-b>SicherheitK</class-b>
<field>
<a>ID</a>
<b>smsID</b>
</field>
</mapping>
What went wrong and what meens "Source field type: generic" ?
Thanks.
Matthias
Logged In: YES
user_id=550744
Can you attach your value objects, mapping file, and unit
test and I will be able to reproduce and (possibly) give you
a fix. The only other time I have seen that error is when
CGLIB was used and the class defined in the mapping file
actually got proxied at runtime so it was not *truly* the
same class as the one in the mapping file.
Thanks,
Franz
Logged In: YES
user_id=1368792
It would be difficult to extract all you need. My Code runs
on Tomcat and uses Spring with Hibernate (on a Oracle-DB) to
map SicherheitK.
So it might be better to move this discussion to Issue
1427982...
I hope to get around this problem by setting lazy="false" in
the Hibernate-Mapping.
In addition the Problem seems to be sporadic.
Was the situation you seen this behaviour also sporadic or
could you reproduce it ?
Logged In: YES
user_id=550744
It was definitely a sporadic thing. It was difficult to
reproduce in a container and impossible to reproduce out of
a container. Are you using deep mappings?
Franz
Logged In: YES
user_id=1368792
Hello Franz,
in the Mapping SicherheitK to SMSSicherheitImpl I use no
deep-mapping. Only one field has two hints.
But in other Mappings I use also deep-Mapping.
Is it a problem to have Mappings without fields (for Example
SicherheitK to Si_GrundpfandrechtImpl which is the one with
the Problem) ?
Matthias
Logged In: YES
user_id=550744
It shouldn't matter that you don't have any fields. On
mappings that are flat we store the Read and Write Method
from the mapped class. Sometimes this changes during mapping
(i.e. CGLIB) but we do validate the class we are mapping is
the same class by running an isAssignable check. I have no
idea why your stuff would fail. We do cache deep hierarchy
information and do not validate that the class we found in
the deep tree is the same one that is trying to be mapped.
hope this helps.
You could step through my code in your container. I would
also be curious to see a stacktrace so i can see what line #
it is blowing up on.
thanks,
franz
Logged In: YES
user_id=1368792
Hello Franz,
did you miss the stacktrace in my note from "2006-05-03 15:58" ?
If I got the time I will try to step through to gather more
information...
Matthias
Logged In: YES
user_id=550744
I should really open my eyes. I think I might know what the
problem is.
Try changing this:
protected Method getReadMethod(Class bean) {
if (readMethod == null ||
!readMethod.getDeclaringClass().isAssignableFrom(bean)) {
if (field.getTheGetMethod() == null) {
readMethod = getReadMethod(clazz, field.getName());
} else {
try {
readMethod = findAMethod(clazz,
field.getTheGetMethod());
} catch (Exception e) {
throw new MappingException(e);
}
}
}
return readMethod;
}
to this:
protected Method getReadMethod(Class bean) {
if (readMethod == null ||
!readMethod.getDeclaringClass().isAssignableFrom(bean)) {
if (field.getTheGetMethod() == null) {
readMethod = getReadMethod(clazz, field.getName());
} else {
try {
readMethod = findAMethod(bean.getClass(),
field.getTheGetMethod());
} catch (Exception e) {
throw new MappingException(e);
}
}
}
return readMethod;
}
Let me know if that works.
Logged In: YES
user_id=550744
or even better:
protected Method getReadMethod(Class bean) {
if (readMethod == null ||
!readMethod.getDeclaringClass().isAssignableFrom(bean)) {
if (field.getTheGetMethod() == null) {
readMethod = getReadMethod(bean.getClass(),
field.getName());
} else {
try {
readMethod = findAMethod(bean.getClass(),
field.getTheGetMethod());
} catch (Exception e) {
throw new MappingException(e);
}
}
}
return readMethod;
}
hello,
I am aware that this issue post is old. I have a question about the same topic :
We have an java application based on OSGI ( Karaf container). We used Dozer as mapper. It is configured and mapped in order to map two models objects related to two layers ( service and persistence).
Our problem is about duplicate class mapping. Firstly the problem has happened randomly and offen occured after each restart of karaf container.
If you want more details, i can share it whit you
Best regards