persistence
persistence copied to clipboard
EntityGraph addAttributeNodes generic type incorrect
The method in EntityGraph (and EntitySubgraph) public void addAttributeNodes(Attribute<T, ?>... attribute);
should be public void addAttributeNodes(Attribute super T, ?>... attribute);
since we should be able to write code like this
EntityGraph<SubEntity> graph = em.createEntityGraph(SubEntity.class); graph.addAttributeNodes(SubEntity_.baseEntityField);
yet currently it is a compiler error due to this generic type bug.
The same applies to other methods that refer to Attribute<T, ?>
- Issue Imported From: https://github.com/javaee/jpa-spec/issues/112
- Original Issue Raised By:@glassfishrobot
- Original Issue Assigned To: @ldemichiel
@glassfishrobot Commented Reported by neilstockton
@glassfishrobot Commented neilstockton said: Perhaps this bug ought to be fixed in JPA 2.2 since it is trivial to do?
@glassfishrobot Commented This issue was imported from java.net JIRA JPA_SPEC-112
@sebek64 Commented Any news on this issue? We have just encountered this issue, and it took a while to figure out that the spec is wrong. For example, the javadoc here http://www.datanucleus.org/javadocs/javax.persistence/2.1/javax/persistence/Subgraph.html seems to have correct types.
I would suggest that you make T an upper bound:
public void addAttributeNodes(Attribute<? super T, ?>... attribute);
My team ran into this issue with a MappedSuperClass that is inherited by two Entities. We would like to consolidate more code that can be shared, but losing the ability to write type safe entity graphs with generated metamodel classes is a show stopper.
This is now being done as part of #424, so this one can probably be closed.