-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-18868 Wrong behaviour of getAttribute method in impl. of ManagedType when scattered id attributes are used in MappedSuperclass #9353
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
182b93a
HHH-18868 Adapted test case from https://hibernate.atlassian.net/brow…
cigaly 296f510
HHH-18868 ID and version properties are handled separately, do not pr…
cigaly aa343f5
HHH-18868 Renamed test classes
cigaly 9fc134d
HHH-18868 Simplified ID property check
cigaly 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
62 changes: 62 additions & 0 deletions
62
hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/hhh18868/BaseSummary.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,62 @@ | ||
| /* | ||
| * SPDX-License-Identifier: LGPL-2.1-or-later | ||
| * Copyright Red Hat Inc. and Hibernate Authors | ||
| */ | ||
| package org.hibernate.orm.test.metamodel.hhh18868; | ||
|
|
||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.IdClass; | ||
| import jakarta.persistence.MappedSuperclass; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.math.BigDecimal; | ||
| import java.util.Objects; | ||
|
|
||
| @IdClass(PKey.class) | ||
| @MappedSuperclass | ||
| public class BaseSummary implements Serializable { | ||
|
|
||
| @Id | ||
| private Integer year; | ||
| @Id | ||
| private Integer month; | ||
| private BigDecimal value; | ||
|
|
||
| public Integer getYear() { | ||
| return year; | ||
| } | ||
|
|
||
| public void setYear(Integer year) { | ||
| this.year = year; | ||
| } | ||
|
|
||
| public Integer getMonth() { | ||
| return month; | ||
| } | ||
|
|
||
| public void setMonth(Integer month) { | ||
| this.month = month; | ||
| } | ||
|
|
||
| public BigDecimal getValue() { | ||
| return value; | ||
| } | ||
|
|
||
| public void setValue(BigDecimal value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if ( o == null || getClass() != o.getClass() ) { | ||
| return false; | ||
| } | ||
| BaseSummary that = (BaseSummary) o; | ||
| return Objects.equals( year, that.year ) && Objects.equals( month, that.month ); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash( year, month ); | ||
| } | ||
| } |
34 changes: 34 additions & 0 deletions
34
hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/hhh18868/HHH18868Test.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,34 @@ | ||
| /* | ||
| * SPDX-License-Identifier: LGPL-2.1-or-later | ||
| * Copyright Red Hat Inc. and Hibernate Authors | ||
| */ | ||
| package org.hibernate.orm.test.metamodel.hhh18868; | ||
|
|
||
| import jakarta.persistence.metamodel.SingularAttribute; | ||
| 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 static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| @DomainModel(annotatedClasses = {Summary.class, BaseSummary.class}) | ||
| @SessionFactory | ||
| @JiraKey( "HHH-18858" ) | ||
| public class HHH18868Test { | ||
cigaly marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @Test | ||
| public void test(SessionFactoryScope scope) { | ||
| scope.inSession( entityManager -> { | ||
| final var yearAttribute = Summary_.year.getDeclaringType().getAttribute( "year" ); | ||
| assertThat( yearAttribute ).isEqualTo( Summary_.year ); | ||
| assertThat( ((SingularAttribute<?, ?>) yearAttribute).isId() ).isTrue(); | ||
|
|
||
| final var monthAttribute = Summary_.month.getDeclaringType().getAttribute( "month" ); | ||
| assertThat( monthAttribute ).isEqualTo( Summary_.month ); | ||
| assertThat( ((SingularAttribute<?, ?>) monthAttribute).isId() ).isTrue(); | ||
| } ); | ||
| } | ||
| } | ||
44 changes: 44 additions & 0 deletions
44
hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/hhh18868/PKey.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,44 @@ | ||
| /* | ||
| * SPDX-License-Identifier: LGPL-2.1-or-later | ||
| * Copyright Red Hat Inc. and Hibernate Authors | ||
| */ | ||
| package org.hibernate.orm.test.metamodel.hhh18868; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.util.Objects; | ||
|
|
||
| public class PKey implements Serializable { | ||
|
|
||
| private Integer year; | ||
| private Integer month; | ||
|
|
||
| public Integer getYear() { | ||
| return year; | ||
| } | ||
|
|
||
| public void setYear(Integer year) { | ||
| this.year = year; | ||
| } | ||
|
|
||
| public Integer getMonth() { | ||
| return month; | ||
| } | ||
|
|
||
| public void setMonth(Integer month) { | ||
| this.month = month; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if ( o == null || getClass() != o.getClass() ) { | ||
| return false; | ||
| } | ||
| PKey pKey = (PKey) o; | ||
| return Objects.equals( year, pKey.year ) && Objects.equals( month, pKey.month ); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash( year, month ); | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/hhh18868/Summary.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,11 @@ | ||
| /* | ||
| * SPDX-License-Identifier: LGPL-2.1-or-later | ||
| * Copyright Red Hat Inc. and Hibernate Authors | ||
| */ | ||
| package org.hibernate.orm.test.metamodel.hhh18868; | ||
|
|
||
| import jakarta.persistence.Entity; | ||
|
|
||
| @Entity | ||
| public class Summary extends BaseSummary { | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.