Closed LukasHaken closed 5 years ago
hey thanks for the bug report. I'll need to have a look, I don't think we can handle that right now. never really thought of that use case.
PS that one might take a while to fix, I don't seen any good solution right now and will need to experiment ...
Hi, thanks for support.
I designed posible solution. It is mainly workaround for me. The solution isn't clearly. So that to be clearly solution, I would have to make big refactoring. My idea is, that every discriminator getter knows, where is discriminator field is in mapping hiearchy. Look at my code and you will surely understand my idea.
my thinking goes along the same line, there is the notion of path of the property, also I'm thinking we could use the prefix of the column name, will need to play about a wee bit. I might just allow both in the end. It's easier for thing like hibernate because they control the sql.
@LukasHaken I have a version kind of ready, needs to figure out the name of some methods as it is rather a lot of discriminator method at the minute ...
@LukasHaken just pushed 7.0.0 with change that should now work for your use case
JdbcMapper<Foo> mapper =
JdbcMapperFactoryHelper.noAsm()
.addKeys("id", "pFirst_id", "pSecond_id")
.discriminator(Parent.class)
.onColumn(CaseInsensitiveEndsWithPredicate.of("class_id"), Integer.class)
.with(builder ->
builder
.when(1, Parent.class)
.when(2, ChildA.class)
.when(3, ChildB.class)
)
.newMapper(Foo.class);
I need 2 different discriminators for same type.
I wrote failing test with my problem. I have class Foo. Foo has 2 association fields pFirst and pSecond, both fields are same class Parent ( has 2 child (ChildA, ChildB)). Field pFirst has own discriminator column name pFirst_class_id and field pSecond has discriminator column name pSecond_class_id. I have instance of Foo, which pFirst is instance of ChildA and pSecond is instance of ChildB. But it doesn't work for me. For pSecond is used discriminator with column name "pFirst_class_id". Test fail on 3. row in method validateMapper.
` public class DiscriminatorJdbcMapperTest2 {
}
`
Am I doing something wrong?