-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-19829 - Deprecate MultiIdentifierLoadAccess and byMultipleIds #11061
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
base: main
Are you sure you want to change the base?
Conversation
7938bbd
to
6eea4ed
Compare
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.
As commented, the record
s would be better as enum
s.
I've left a couple of comments about minor stuff.
hibernate-core/src/test/java/org/hibernate/orm/test/loading/multiLoad/MultiLoadTest.java
Outdated
Show resolved
Hide resolved
loadAccess.withReadOnly( option == ReadOnlyMode.READ_ONLY ); | ||
} | ||
else if ( option instanceof MultiFindOption multiFindOption ) { | ||
throw new IllegalArgumentException( "MultiFindOption " + multiFindOption.toString() + " can only be used in multi-find operations" ); |
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.
throw new IllegalArgumentException( "MultiFindOption " + multiFindOption.toString() + " can only be used in multi-find operations" ); | |
throw new IllegalArgumentException( "Option '" + multiFindOption + "' can only be used in 'findMultiple()'" ); |
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.
@jrenaat Why did you mark this suggestion as resolved?
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.
Because I adopted it as suggested (it just wasn't pushed to my PR yet)
/** | ||
* Simple marker interface for FindOptions which can be applied to multiple id loading. | ||
*/ | ||
public interface MultiFindOption extends FindOption { |
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.
One more thing, since MultiFindOption
:
- doesn't actually add any type safety (it extends
MultiFindOption
) - has a quite ugly name
- can be added into the hierarchy at any time if needed
I would just remove it, and make these new options implement FindOption
directly.
It's not adding anything.
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.
It was steve's suggestion to do it like this.
It does make the restriction in session.find(..., FindOption ... options)
somewhat cleaner having it around
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.
It does make the restriction in
session.find(..., FindOption ... options)
somewhat cleaner having it around
I don't know what you mean by this.
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.
private <T> void setLoadAccessOptions(FindOption[] options, IdentifierLoadAccessImpl<T> loadAccess) {
for ( FindOption option : options ) {
if ( option instance of MultiFindOption ) {
throw ...
}
}
}
is quite nicer than individually checking for each type.
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.
It's not adding anything.
I disagree. Find usages of MultiFindOption has value.
has a quite ugly name
Your opinion.
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.
is quite nicer than individually checking for each type.
Which is what I meant
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.
So if you really insist on retaining it (I would not, since this is the root package org.hibernate
) then how about FindMultipleOption
, to reflect that it is an option for the findMultiple()
method?
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.
I was going to make a few suggestions about Javadoc but I'll just adjust those later.
/** | ||
* Simple marker interface for FindOptions which can be applied to multiple id loading. | ||
*/ | ||
public interface MultiFindOption extends FindOption { |
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.
private <T> void setLoadAccessOptions(FindOption[] options, IdentifierLoadAccessImpl<T> loadAccess) {
for ( FindOption option : options ) {
if ( option instance of MultiFindOption ) {
throw ...
}
}
}
is quite nicer than individually checking for each type.
I went back and forth on this. Better in terms of comparison for sure. |
I think this is somewhat a matter of personal taste? |
Neither of those code fragments show usage of The difference with an Otherwise, the two options are equivalent. If you really want an public enum ReadOnlyMode implements FindOption {
READ_ONLY, READ_WRITE;
public boolean enabled() {
return this != READ_WRITE;
}
} vs: public record ReadOnlyMode(boolean enabled) implements FindOption {
public static final READ_ONLY = new ReadOnlyMode(true);
public static final READ_WRITE = new ReadOnlyMode(false);
}
Folks, this is what |
To model booleans... Got it... |
MultiIdentifierLoadAccess is being deprecated. That's what you are doing. So that's not really relevant. We will likely leave it as an internal contract, but the deprecation is about removing it as an API. |
Boolean is a perfect example of an enumerated type! In languages like Ceylon or Haskell where e.g. Haskell: |
The point is about enums wrapping booleans, not booleans-as-enum |
I understand. We are defining types which are isomorphic to What I'm saying is that if Java didn't have a primitive Because that way the compiler knows there are only two values of the type. The compiler has no way of reasoning about the possible values of a Therefore, if we're asking what's the natural way to implement a type which is isomorphic to I'm not saying it makes a massive difference in practice; it doesn't. It's just a more natural use of the Java language. |
Anyway, look, if you don't find those arguments convincing, that's fine. But we already have the precedent of:
which are all enums isomorphic to Unless ya'll can think of some particular reason why users should be allowed to write |
I think I already hinted I was going that way. You just felt the need to go off on a tangent. |
I think clearly indicates a leaning ;) |
OK, great. I read it as skepticism. |
This is the actual first time i can clearly indicate the trigger of one of my migraines ... :-| |
…e in findMultiple() Signed-off-by: Jan Schatteman <[email protected]>
…dMultiple instead of byMultipleIds, thus covering the newly introduced MultiFindOptions Signed-off-by: Jan Schatteman <[email protected]>
…tipleIds() methods Signed-off-by: Jan Schatteman <[email protected]>
…ations Signed-off-by: Jan Schatteman <[email protected]>
6eea4ed
to
204da85
Compare
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.
https://hibernate.atlassian.net/browse/HHH-19829