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
Generic metamodel attribute should be resolved as concrete as possible #562
Comments
Well, that would be a breaking change, so we can't do that. Also, to handle generics correctly, the method would need to return a So it would have to be a new method. But honestly I just don't see this as a very high priority at all. Entities don't usually benefit from parametric polymorphism, since they must be mapped to a database table which is not generic. In the particular example shown, it's quite easy to move the mapping for |
Let's discuss the real impact of this change, I think it's a enhancement instead of breaking change.
I agree that, but it should be discussed in another feature request issue.
Moving the field down add lots of boilerplate code is not elegant, and lots of existing code need changes to adapt the breaking change which introduced by Hibernate 6. |
I think you're underestimating this. If it's worth doing, it's worth doing properly. First of all, if we're going to have metamodel objects representing actualized versions of inherited members, the first thing I want to know is: what is the way to get hold of these things via the static metamodel. Now, that's a solvable problem, but we would have to solve it. Second, consider the signature of this method: Attribute<? super X, ?> getAttribute(String name); That's actually wrong for the operation you're proposing. The correct signature would be: Attribute<X, ?> getActualAttribute(String name); without the wildcard. Now, perhaps it's not that big of a deal, but it's still a whole new operation, along with the addition of an operation on So in the end that's—just right off the top of my head—much more than a trivial change for something that's of pretty marginal value. |
"as concrete as possible" as title said, If it's not possible then fall back to current behavior. |
So you would rather have entityManager.getMetamodel().entity(Book.class).getAttribute("owner").getJavaType() return the concrete type i.e. If the JPA spec ought to handle generics, it will need a new API for that. |
I'm not sure I understand what you means, for other subclass such as @Entity
public class House extends OwnerContainer<HouseOwner> {
@Id
private Long id;
}
@Entity
public class HouseOwner {
@Id
private Long id;
} then entityManager.getMetamodel().entity(House.class).getAttribute("owner").getJavaType() should return |
I guess you mean entityManager.getMetamodel().entity(House.class).getAttribute("owner").getJavaType() should return This is where you seem to lack an understanding of how the metamodel is structured. An attribute is declared by a managed type and clearly |
Yes, It's a typo.
that's why I'm opening this issue, there is something need to improve at specification level, and It's a small fix for hibernate. For an given entity, the |
For static metamodel, It should generated like this: @StaticMetamodel(OwnerContainer.class)
public abstract class OwnerContainer_ {
public static volatile SingularAttribute<OwnerContainer, Object> owner;
}
@StaticMetamodel(Book.class)
public abstract class Book_ {
public static volatile SingularAttribute<Book, Long> id;
public static volatile SingularAttribute<Book, Owner> owner; // The missing part
} |
I've tested with EclipseLink 3.0.4, It does return the expected |
Not a single person here claimed that it cannot be done. The claim is that it would be wrong and inelegant to do so. As I've already said above, it's pretty clear from the signature of the method (i.e. from its return type) that that operation is supposed to return the member as declared by the supertype. See that wildcard there? It's there for a reason, not just for decoration! If the operation were supposed to behave the way you claim it should behave, that is, if it were supposed to return the member as actually inherited by the subtype then its signature would be
But the words "or inherited" just aren't there. I added them in right now. Now, do the spec and Javadoc leave some ambiguity here, well, yeah, sure they do, and that's a bit unfortunate. But I insist that the most reasonable interpretation is that the JPA metamodel works just like the Java reflection API in this aspect. So sure, this issue can be solved: properly, by introducing a new operation with the correct signature, in a future version of JPA (i.e. |
IMO, there is no need to introduce a new method I repeat my request in a nutshell:
Wish other developers state their opinions here too. |
Given
Then
Should return
Owner.class
instead of erased typeObject.class
see hibernate/hibernate-orm#7630 (comment)
The text was updated successfully, but these errors were encountered: