-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-16514 - Property sorting can lead to incorrect column mappings wi…
…th derived embeddable keys (cherry picked from commit 60b6fe3)
- Loading branch information
Showing
4 changed files
with
134 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
34 changes: 34 additions & 0 deletions
34
hibernate-core/src/test/java/org/hibernate/orm/test/foreignkeys/sorting/A.java
This file contains 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 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. | ||
*/ | ||
package org.hibernate.orm.test.foreignkeys.sorting; | ||
|
||
import jakarta.persistence.CascadeType; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.ManyToOne; | ||
|
||
/** | ||
* @author Steve Ebersole | ||
*/ | ||
@Entity | ||
public class A { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private int id; | ||
|
||
@ManyToOne(cascade = CascadeType.PERSIST) | ||
B b; | ||
|
||
public A() { | ||
} | ||
|
||
public A(B b) { | ||
this.b = b; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
hibernate-core/src/test/java/org/hibernate/orm/test/foreignkeys/sorting/B.java
This file contains 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,51 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. | ||
*/ | ||
package org.hibernate.orm.test.foreignkeys.sorting; | ||
|
||
import java.math.BigDecimal; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.Id; | ||
|
||
/** | ||
* @author Steve Ebersole | ||
*/ | ||
@Entity | ||
public class B { | ||
enum Type {ONE,ANOTHER} | ||
|
||
@Id | ||
@Column(length = 12) | ||
String code; | ||
|
||
@Id | ||
@Column(precision = 10, scale = 0) | ||
BigDecimal cost; | ||
|
||
@Id | ||
@Enumerated(EnumType.STRING) | ||
Type type; | ||
|
||
@Id | ||
long id; | ||
|
||
String name; | ||
|
||
public B() { | ||
} | ||
|
||
public B(String code, BigDecimal cost, Type type, long id, String name) { | ||
this.code = code; | ||
this.cost = cost; | ||
this.type = type; | ||
this.id = id; | ||
this.name = name; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...rc/test/java/org/hibernate/orm/test/foreignkeys/sorting/ForeignKeyColumnSortingTests.java
This file contains 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,42 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. | ||
*/ | ||
package org.hibernate.orm.test.foreignkeys.sorting; | ||
|
||
import java.math.BigDecimal; | ||
|
||
import org.hibernate.testing.orm.junit.DomainModel; | ||
import org.hibernate.testing.orm.junit.Jira; | ||
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; | ||
|
||
/** | ||
* @author Steve Ebersole | ||
*/ | ||
@DomainModel(annotatedClasses = { A.class, B.class }) | ||
@SessionFactory | ||
public class ForeignKeyColumnSortingTests { | ||
@Test | ||
@Jira( "https://hibernate.atlassian.net/browse/HHH-16514" ) | ||
public void testDerivedCompositeFk(SessionFactoryScope sfScope) { | ||
|
||
sfScope.inTransaction( (session) -> { | ||
final B b = new B( "abc", new BigDecimal( 1 ), B.Type.ONE, 1L, "tester" ); | ||
session.persist( b ); | ||
session.persist( new A( b ) ); | ||
} ); | ||
|
||
sfScope.inTransaction( (session) -> { | ||
final A loaded = session.get( A.class, 1 ); | ||
assertThat( loaded ).isNotNull(); | ||
assertThat( loaded.b ).isNotNull(); | ||
assertThat( loaded.b.name ).isEqualTo( "tester" ); | ||
} ); | ||
} | ||
} |