Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about discriminator mapping. #769

Open
Gungrave223 opened this issue Nov 30, 2021 · 1 comment
Open

Question about discriminator mapping. #769

Gungrave223 opened this issue Nov 30, 2021 · 1 comment

Comments

@Gungrave223
Copy link

Gungrave223 commented Nov 30, 2021

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?

@abigailCortis
Copy link

Do we have to create a discriminator for each property defined in the child classes? Because at the moment that is the only way that worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants