arnaudroger / SimpleFlatMapper

Fast and Easy mapping from database and csv to POJO. A java micro ORM, lightweight alternative to iBatis and Hibernate. Fast Csv Parser and Csv Mapper
http://simpleflatmapper.org
MIT License
435 stars 76 forks source link

Question about discriminator mapping. #769

Open Gungrave223 opened 2 years ago

Gungrave223 commented 2 years ago

Background.... let say I have 3 classes as such.

class User {
 private int id;
 private int username;
.....
}

class Teacher  extends User {
 private int role;
.....
}

class Student extends User {
 private Detail details;
.....
}

And I define my mapping base on the example as follow...

JdbcTemplateMapperFactory<Person> mapper =
        JdbcTemplateMapperFactory.newInstance()
                .addKeys("id")
                .discriminator(Users.class)
                .onColumn("type", Integer.class)
                .with( 
                    builder -> 
                        builder
                            .when(0, Student.class)
                            .when(1, Teacher.class)
                )
                .newResultSetExtractor(User.class);

I'm current getting the unknown property exception on values that's not apart of the base User class Could not find eligible property for 'Role' on class com.example.User not found

So I would imagine that I need to map the properties for the sub class like I would n to n or n to m relationships but I'm not sure how to accomplish that .... any input into the matter?