-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-16383 - NaturalIdClass #11301
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
Open
sebersole
wants to merge
5
commits into
hibernate:main
Choose a base branch
from
sebersole:naturalidclass
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,964
−1,687
Open
HHH-16383 - NaturalIdClass #11301
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * Copyright Red Hat Inc. and Hibernate Authors | ||
| */ | ||
| package org.hibernate; | ||
|
|
||
| import jakarta.persistence.FindOption; | ||
|
|
||
| /// FindOption allowing to load based on either id (default) | ||
| /// or natural-id. | ||
| /// | ||
| /// @see jakarta.persistence.EntityManager#find | ||
| /// @see Session#findMultiple | ||
| /// | ||
| /// @author Steve Ebersole | ||
| /// @author Gavin King | ||
| public enum FindBy implements FindOption { | ||
| /// Indicates to find by the entity's identifier. The default. | ||
| /// | ||
| /// @see jakarta.persistence.Id | ||
| /// @see jakarta.persistence.EmbeddedId | ||
| /// @see jakarta.persistence.IdClass | ||
| ID, | ||
|
|
||
| /// Indicates to find based on the entity's natural-id, if one. | ||
| /// | ||
| /// @see org.hibernate.annotations.NaturalId | ||
| /// @see org.hibernate.annotations.NaturalIdClass | ||
| /// | ||
| /// @implSpec Will trigger an [IllegalArgumentException] if the entity does | ||
| /// not define a natural-id. | ||
| NATURAL_ID | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
hibernate-core/src/main/java/org/hibernate/NaturalIdSynchronization.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * Copyright Red Hat Inc. and Hibernate Authors | ||
| */ | ||
| package org.hibernate; | ||
|
|
||
| import jakarta.persistence.FindOption; | ||
|
|
||
| /// Indicates whether to perform synchronization (a sort of flush) | ||
| /// before a [find by natural-id][FindBy#NATURAL_ID]. | ||
| /// | ||
| /// @author Steve Ebersole | ||
| public enum NaturalIdSynchronization implements FindOption { | ||
| /// Perform the synchronization. | ||
| ENABLED, | ||
|
|
||
| /// Do not perform the synchronization. | ||
| DISABLED; | ||
| } |
2,436 changes: 1,133 additions & 1,303 deletions
2,436
hibernate-core/src/main/java/org/hibernate/Session.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
hibernate-core/src/main/java/org/hibernate/annotations/NaturalIdClass.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * Copyright Red Hat Inc. and Hibernate Authors | ||
| */ | ||
| package org.hibernate.annotations; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
| import java.lang.annotation.Retention; | ||
|
|
||
| /// Models a non-aggregated composite natural-id for the purpose of loading. | ||
| /// The non-aggregated form uses multiple [@NaturalId][NaturalId] as opposed | ||
| /// to the aggregated form which uses a single [@NaturalId][NaturalId] combined | ||
| /// with [@Embedded][jakarta.persistence.Embedded]. | ||
| /// Functions in a similar fashion as [@IdClass][jakarta.persistence.IdClass] for | ||
| /// non-aggregated composite identifiers. | ||
| /// | ||
| /// ```java | ||
| /// @Entity | ||
| /// @NaturalIdClass(OrderNaturalId.class) | ||
| /// class Order { | ||
| /// @Id | ||
| /// Integer id; | ||
| /// @NaturalId @ManyToOne | ||
| /// Customer customer; | ||
| /// @NaturalId | ||
| /// Integer orderNumber; | ||
| /// ... | ||
| /// } | ||
| /// | ||
| /// class OrderNaturalId { | ||
| /// Integer customer; | ||
| /// Integer orderNumber; | ||
| /// ... | ||
| /// } | ||
| /// ``` | ||
| /// | ||
| /// @see NaturalId | ||
| /// @see jakarta.persistence.IdClass | ||
| /// | ||
| /// @author Steve Ebersole | ||
| @Target(ElementType.TYPE) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| public @interface NaturalIdClass { | ||
| /// The class to use for loading the associated entity by natural-id. | ||
| Class<?> value(); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Missing catch of NumberFormatException Note