-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jan Schatteman <[email protected]>
- Loading branch information
Showing
2 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
...ate-core/src/test/java/org/hibernate/orm/test/records/ElementCollectionOfRecordsTest.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,88 @@ | ||
/* | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
* Copyright Red Hat Inc. and Hibernate Authors | ||
*/ | ||
package org.hibernate.orm.test.records; | ||
|
||
import jakarta.persistence.ElementCollection; | ||
import jakarta.persistence.Embeddable; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.OrderColumn; | ||
import jakarta.persistence.OrderBy; | ||
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 java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* @author Jan Schatteman | ||
*/ | ||
@SessionFactory | ||
@DomainModel(annotatedClasses = {ElementCollectionOfRecordsTest.MainEntity.class}) | ||
public class ElementCollectionOfRecordsTest { | ||
|
||
@Test | ||
@Jira( "https://hibernate.atlassian.net/browse/HHH-18957" ) | ||
public void testInsertOrderOfRecordsInElementCollection(SessionFactoryScope scope) { | ||
scope.inTransaction( | ||
session -> { | ||
MainEntity me = new MainEntity(); | ||
me.setId( 1L ); | ||
me.addRecord( new Record( "c", "a", "b", 2L ) ); | ||
me.addRecord( new Record( "2c", "a2", "bb", 22L ) ); | ||
session.persist( me ); | ||
} | ||
); | ||
scope.inTransaction( | ||
session -> { | ||
MainEntity me = session.find( MainEntity.class, 1L ); | ||
List<Record> records = me.getRecords(); | ||
assertEquals(2, records.size()); | ||
Record r = records.get( 0 ); | ||
assertEquals("a", r.aField); | ||
assertEquals("b", r.bField); | ||
assertEquals("c", r.cField); | ||
assertEquals(2L, r.longField); | ||
r = records.get( 1 ); | ||
assertEquals("a2", r.aField); | ||
assertEquals("bb", r.bField); | ||
assertEquals("2c", r.cField); | ||
assertEquals(22L, r.longField); | ||
} | ||
); | ||
} | ||
|
||
@Entity(name = "MainEntity") | ||
public static class MainEntity { | ||
@Id | ||
Long id; | ||
|
||
@OrderColumn | ||
@ElementCollection(fetch = FetchType.EAGER) | ||
@OrderBy("longField") | ||
List<Record> records = new ArrayList<>(); | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public void addRecord(Record r) { | ||
this.records.add( r ); | ||
} | ||
|
||
public List<Record> getRecords() { | ||
return records; | ||
} | ||
} | ||
|
||
@Embeddable | ||
public record Record(String cField, String aField, String bField, Long longField) {} | ||
} |
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