HHH-14069 Testcase
LazyLoading with @Inheritance(SINGLE_TABLE) doesn't honor the discriminator value, which result in a WrongClassException
I understand that this sort of mapping is usually handled using the @Where annotations, as described in the documentation here:
Hallo @gavinking, thanks for the reply. Your suggestion is a workable workaround and in the end, we use it. In my opinion this bug is critical, for the following reasons:
- First, if you are not familiar with hibernate the behavior is strange and cost you hours of debugging and finding a solution for this problem.
- Second you can run in a situation that you are using unnoticed wrong objects. As a user you see objects of class A, but the objects are of class B.
Is there a realistic chance to fix the Bug? And if not, can you give me a hint to fix the bug and provide it here in the PR? Thanks in advance.
Well, yes, I believe it's in-principle fixable (perhaps quite easily fixable) by adding a discriminator column to the join.
We discussed it here:
And I also commented about the issue here:
https://github.com/eclipse-ee4j/jpa-api/issues/39#issuecomment-830112571
Now, I think this would be nice to fix, and I might look at it myself if/when I find time, but as I said in those threads, I definitely don't think it's "critical". Mapping two different associations to the same FK column is pretty strange thing to do to begin with, and if you do do this strange thing then the @Where() workaround isn't so awful.
If you want to try, the trick is to convince Hibernate to add the discriminator column to the table join in single table inheritance mappings. That's probably pretty straightforward. The trickier part, I imagine, is detecting when you need to do this. The problem is that Hibernate simply doesn't know that you mapped two different associations to the same FK column. You need to detect that. Perhaps it's not so hard, I'm not sure.
The problem is that Hibernate simply doesn't know that you mapped two different associations to the same FK column. You need to detect that. Perhaps it's not so hard, I'm not sure.
And for consistency, you probably even need to detect it when the associations belong to different entities.
The problem is that Hibernate simply doesn't know that you mapped two different associations to the same FK column. You need to detect that. Perhaps it's not so hard, I'm not sure.
And for consistency, you probably even need to detect it when the associations belong to different entities.
Actually that's not right: probably the right thing to do is to detect that the association references a type whose discriminator column is declared by a supertype.
I believe that #4200 demonstrates that this now works in H6.
I don't think we should try to fix this in H5.
So I recommend closing this PR.