-
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.
(cherry picked from commit 502fd78)
- Loading branch information
Showing
1 changed file
with
146 additions
and
0 deletions.
There are no files selected for viewing
146 changes: 146 additions & 0 deletions
146
...-core/src/test/java/org/hibernate/test/batchfetch/BatchFetchReferencedColumnNameTest.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,146 @@ | ||
/* | ||
* 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.test.batchfetch; | ||
|
||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; | ||
|
||
import java.time.ZonedDateTime; | ||
import java.util.List; | ||
|
||
import javax.persistence.CascadeType; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.OneToMany; | ||
import javax.persistence.OrderBy; | ||
import javax.persistence.Table; | ||
|
||
import org.hibernate.cfg.AvailableSettings; | ||
import org.hibernate.cfg.Configuration; | ||
import org.hibernate.testing.TestForIssue; | ||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class BatchFetchReferencedColumnNameTest extends BaseCoreFunctionalTestCase { | ||
|
||
@Override | ||
protected Class<?>[] getAnnotatedClasses() { | ||
return new Class<?>[]{ Child.class, Parent.class }; | ||
} | ||
|
||
@Override | ||
protected void configure(Configuration configuration) { | ||
super.configure( configuration ); | ||
|
||
configuration.setProperty( AvailableSettings.SHOW_SQL, Boolean.TRUE.toString() ); | ||
configuration.setProperty( AvailableSettings.FORMAT_SQL, Boolean.TRUE.toString() ); | ||
|
||
configuration.setProperty( AvailableSettings.DEFAULT_BATCH_FETCH_SIZE, "64" ); | ||
} | ||
|
||
@Test | ||
@TestForIssue(jiraKey = "HHH-13059") | ||
public void test() throws Exception { | ||
doInHibernate( this::sessionFactory, session -> { | ||
Parent p = new Parent(); | ||
p.setId( 1L ); | ||
session.save( p ); | ||
|
||
Child c1 = new Child(); | ||
c1.setCreatedOn( ZonedDateTime.now() ); | ||
c1.setParentId( 1L ); | ||
c1.setId( 10L ); | ||
session.save( c1 ); | ||
|
||
Child c2 = new Child(); | ||
c2.setCreatedOn( ZonedDateTime.now() ); | ||
c2.setParentId( 1L ); | ||
c2.setId( 11L ); | ||
session.save( c2 ); | ||
} ); | ||
|
||
doInHibernate( this::sessionFactory, session -> { | ||
Parent p = session.get( Parent.class, 1L ); | ||
Assert.assertNotNull( p ); | ||
|
||
Assert.assertEquals( 2, p.getChildren().size() ); | ||
} ); | ||
} | ||
|
||
@Entity | ||
@Table(name = "CHILD") | ||
public static class Child { | ||
|
||
@Id | ||
@Column(name = "CHILD_ID") | ||
private Long id; | ||
|
||
@Column(name = "PARENT_ID") | ||
private Long parentId; | ||
|
||
@Column(name = "CREATED_ON") | ||
private ZonedDateTime createdOn; | ||
|
||
public ZonedDateTime getCreatedOn() { | ||
return createdOn; | ||
} | ||
|
||
public void setCreatedOn(ZonedDateTime createdOn) { | ||
this.createdOn = createdOn; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public Long getParentId() { | ||
return parentId; | ||
} | ||
|
||
public void setParentId(Long parentId) { | ||
this.parentId = parentId; | ||
} | ||
} | ||
|
||
@Entity | ||
@Table(name = "PARENT") | ||
public static class Parent { | ||
|
||
@Id | ||
@Column(name = "PARENT_ID") | ||
private Long id; | ||
|
||
@OneToMany(fetch = FetchType.EAGER, cascade = { CascadeType.ALL }) | ||
@JoinColumn(name = "PARENT_ID", referencedColumnName = "PARENT_ID") | ||
@OrderBy("createdOn desc") | ||
private List<Child> children; | ||
|
||
public List<Child> getChildren() { | ||
return children; | ||
} | ||
|
||
public void setChildren(List<Child> children) { | ||
this.children = children; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
} | ||
} |