The only “bug” here is that we are not throwing a more informative exception. A case expression requires that the result arms produce a scalar result and an entity is definitely not a scalar result. The underlying SQL will have to select columns for both associations anyway. I can be convinced that this can be viewed as a nice new feature, but at the same time, I don’t see how a case when expression greatly improves anything vs. retrieving both associations as result and you doing that check in Java code. There are actually some pretty hard problems here that we would have to handle if we wanted to support this, like selecting which columns to use for rendering the expression. In a select item you want to select everything, but in a predicate, you probably want the FK/PK, but if you use different associations which have different mappings, this is turns out to become a pretty annoying problem to solve in general. We already have a bunch of code that tries to handle all possible cases of comparing two entity valued paths and that is pretty complex already because there are so many cases to consider. I think that deciding on the columns when even more paths are involved is going to be even messier. What do you mean by this worked in Hibernate 5? Can you please create a test case that reproduces this scenario? |