Hi i got the code below :
ModuleA.Student student 1 = null;
ModuleB.Student student 2 = null;
student2 = retrieveStudentFacade().findStudentbyName("John");
student1 = StudentSessionEJBBean.convert(student2,ModuleA.Student.Class);
The problem now student1.getId(); return null but supposed to return me a value. Below is the converter method, someone guide me using this method to reflect the objects. It works nice as no error occur just no value return?
UPDATE
public static <A,B> B convert(A instance, Class<B> targetClass) throws Exception {
B target = (B) targetClass.newInstance();
for (Field targetField: targetClass.getDeclaredFields()) {
Field field = instance.getClass().getDeclaredField(targetField.getName());
field.setAccessible(true);
targetField.set(target, field.get(instance));
}
return target;
}