-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
HHH-18714 add support for inheritance in entity graph #9088
base: 6.6
Are you sure you want to change the base?
Conversation
.../org/hibernate/orm/test/entitygraph/named/multiple/NamedEntityGraphsWithInheritanceTest.java
Outdated
Show resolved
Hide resolved
...te-core/src/test/java/org/hibernate/orm/test/entitygraph/EntityGraphWithInheritanceTest.java
Outdated
Show resolved
Hide resolved
@gavinking I don't understand why h2 build fail. Do I need to relaunch the build for h2? Is it possible that this is coming from Edit: Its work now |
Maybe I had spaces instead of tabs in my suggestion. |
I think it was me, I had forgotten some unused imports. |
Hello @gavinking What do you think of this change ? Should I plan to add documentation on how it works, or is it too risky ? |
this.name = name; | ||
this.subclassSubgraphs = new HashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should IMO be instantiated lazily.
PersistentAttribute<?, ?> attribute = managedType.findAttributeInSuperTypes( attributeName ); | ||
|
||
if ( attribute == null ) { | ||
attribute = managedType.findSubTypesAttribute( attributeName ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert this. Implicitly looking into subtypes is not an option. Users will have to explicitly cast the graph to "treat" it and can then access subtype attributes.
SubGraphImplementor<S> subgraph = new SubGraphImpl<>( subTypeEntityDomainType, true ); | ||
|
||
subclassSubgraphs.putIfAbsent( subTypeEntityDomainType, subgraph ); | ||
|
||
return subgraph; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sub-graph needs to know about this
since the javadoc of addTreatedSubgraph
says:
Subclass subgraphs automatically include the specified attributes of superclass subgraphs.
also, I think it's desirable to return an existing instance:
SubGraphImplementor<S> subgraph = new SubGraphImpl<>( subTypeEntityDomainType, true ); | |
subclassSubgraphs.putIfAbsent( subTypeEntityDomainType, subgraph ); | |
return subgraph; | |
final SubGraphImplementor<?> existingSubgraph = subclassSubgraphs.get( subTypeEntityDomainType ); | |
if ( existingSubgraph != null ) { | |
return existingSubgraph; | |
} | |
final SubGraphImplementor<S> subgraph = new SubGraphImpl<>( subTypeEntityDomainType, true ); | |
subclassSubgraphs.put( subTypeEntityDomainType, subgraph ); | |
return subgraph; |
); | ||
} | ||
if ( StringHelper.isNotEmpty( namedAttributeNode.keySubgraph() ) ) { | ||
final SubGraphImplementor<?> subgraph = attributeNode.makeKeySubGraph(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using this method to create a sub-graph for a map-key is vital. This change won't work if a key subgraph uses a subtype subgraph with the same type as a value subgraph.
GraphImplementor mergedSubgraph = new SubGraphImpl<>( managedDomainType, true ); | ||
|
||
for ( GraphImplementor subgraph : subgraphMap.values() ) { | ||
mergedSubgraph.merge( subgraph ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will not be necessary anymore once the SubGraphImpl
knows of its parent like the spec requires it. See my previous comment.
[Please describe here what your change is about]
This change enables support for inheritance with EntityGraphs as described in the JPA specification.
I've added some functions such as
addTreatedSubgraph
to facilitate future integration with Hibernate 7 (Jpa 3.2).The ticket related to my proposal: https://hibernate.atlassian.net/browse/HHH-18714
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.