Skip to content

Question about discriminator mapping. #769

@Gungrave223

Description

@Gungrave223

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions