-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-19706 Composite @Id with a generic part in @MappedSuperclass #10749
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
cigaly
wants to merge
2
commits into
hibernate:main
from
cigaly:HHH-19706-Composite_@Id_with_a_generic_part_in_@MappedSuperclass
+96
−2
Open
Changes from all commits
Commits
Show all changes
2 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
94 changes: 94 additions & 0 deletions
...m/test/mapping/generics/compositeid/CompositeIdWithGenericPartInMappedSuperclassTest.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,94 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright Red Hat Inc. and Hibernate Authors | ||
*/ | ||
package org.hibernate.orm.test.mapping.generics.compositeid; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.IdClass; | ||
import jakarta.persistence.MappedSuperclass; | ||
import org.hibernate.testing.orm.junit.DomainModel; | ||
import org.hibernate.testing.orm.junit.JiraKey; | ||
import org.hibernate.testing.orm.junit.SessionFactory; | ||
import org.hibernate.testing.orm.junit.SessionFactoryScope; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.Serializable; | ||
import java.util.Objects; | ||
|
||
@JiraKey("HHH-19706") | ||
@DomainModel( | ||
annotatedClasses = { | ||
CompositeIdWithGenericPartInMappedSuperclassTest.SampleCompositeIdEntity.class, | ||
CompositeIdWithGenericPartInMappedSuperclassTest.SampleEntity.class, | ||
CompositeIdWithGenericPartInMappedSuperclassTest.SampleSuperclass.class | ||
} | ||
) | ||
@SessionFactory | ||
class CompositeIdWithGenericPartInMappedSuperclassTest { | ||
|
||
@Test | ||
void test(SessionFactoryScope scope) { | ||
scope.inSession( s -> s.createQuery( "from SampleEntity", SampleEntity.class ).getResultList() ); | ||
} | ||
|
||
@Entity | ||
@IdClass(SampleCompositeIdEntity.AdditionalIdEntityId.class) | ||
static class SampleCompositeIdEntity extends SampleSuperclass<Long> { | ||
|
||
@Id | ||
@Column(nullable = false, updatable = false) | ||
private Long additionalId; | ||
|
||
static class AdditionalIdEntityId implements Serializable { | ||
|
||
final Long mainId; | ||
final Long additionalId; | ||
|
||
public AdditionalIdEntityId() { | ||
this( 0L, 0L ); | ||
} | ||
|
||
public AdditionalIdEntityId(Long mainId, Long additionalId) { | ||
this.mainId = mainId; | ||
this.additionalId = additionalId; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if ( this == o ) { | ||
return true; | ||
} | ||
if ( !(o instanceof AdditionalIdEntityId) ) { | ||
return false; | ||
} | ||
AdditionalIdEntityId key = (AdditionalIdEntityId) o; | ||
return Objects.equals( mainId, key.mainId ) && Objects.equals( additionalId, key.additionalId ); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash( mainId, additionalId ); | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
@Entity(name = "SampleEntity") | ||
static class SampleEntity extends SampleSuperclass<Long> { | ||
|
||
private String sampleField; | ||
|
||
} | ||
|
||
@MappedSuperclass | ||
abstract static class SampleSuperclass<K extends Serializable & Comparable<K>> { | ||
|
||
@Id | ||
private K mainId; | ||
|
||
} | ||
} |
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.