0

We're using MyBatis with XMLs to map DB tables to Java POJOs. I'm facing an issue because we've a wrapper class for POJO fields. The structure is as follows:

Wrapper class:

class ColumnWrapper<T> {
    T value;
    T nextValue;
}

Class to be mapped with DB table:

class ParentClass {
    ColumnWrapper<String> stringField;
    ColumnWrapper<CompositeClass> compositeClass;
    ... other fields and getter/setters
}

Composite class is a simple POJO:

class CompositeClass {
    String compositeField1;
    Integer compositeField2;
}

I wrote a TypeHandler for ColumnWrapper<String> and it is working fine for stringField. But I'm not able to map ColumnWrapper<CompositeClass> compositeClass field. I tried creating TypeHandler for it but it's not working. Can anyone please help with it?

VaibS
  • 1,627
  • 1
  • 15
  • 21
  • Type handler maps one column value to one property, and vice versa. It's unclear if it fits your use case because you didn't post any information about the result set or mapper statement. Also, such usage of generics requires rather cumbersome configuration partly because of type erasure. If possible, you should create a new class for each type parameter e.g. `class StringColumn extends ColumnWrapper {}`. – ave Mar 19 '23 at 19:57

0 Answers0