HHH-11459 - Test case
This commit is contained in:
parent
a5c7087316
commit
2779ebd8f0
|
@ -8,6 +8,9 @@ package org.hibernate.test.bytecode.enhancement;
|
|||
|
||||
import org.hibernate.bytecode.enhance.spi.UnloadedClass;
|
||||
|
||||
import org.hibernate.bytecode.enhance.spi.UnloadedField;
|
||||
import org.hibernate.test.bytecode.enhancement.merge.MergeEnhancedEntityTestTask;
|
||||
import org.hibernate.test.bytecode.enhancement.merge.RefreshEnhancedEntityTestTask;
|
||||
import org.hibernate.testing.DialectChecks;
|
||||
import org.hibernate.testing.FailureExpected;
|
||||
import org.hibernate.testing.RequiresDialectFeature;
|
||||
|
@ -95,6 +98,13 @@ public class EnhancerTest extends BaseUnitTestCase {
|
|||
EnhancerTestUtils.runEnhancerTestTask( DetachedGetIdentifierTestTask.class );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-11459" )
|
||||
public void testMergeRefresh() {
|
||||
EnhancerTestUtils.runEnhancerTestTask( MergeEnhancedEntityTestTask.class );
|
||||
EnhancerTestUtils.runEnhancerTestTask( RefreshEnhancedEntityTestTask.class );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEviction() {
|
||||
EnhancerTestUtils.runEnhancerTestTask( EvictionTestTask.class );
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* 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.bytecode.enhancement.merge;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.test.bytecode.enhancement.AbstractEnhancerTestTask;
|
||||
import org.junit.Assert;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Luis Barreiro
|
||||
*/
|
||||
public class MergeEnhancedEntityTestTask extends AbstractEnhancerTestTask {
|
||||
|
||||
private long entityId;
|
||||
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[]{Person.class, PersonAddress.class};
|
||||
}
|
||||
|
||||
public void prepare() {
|
||||
Configuration cfg = new Configuration();
|
||||
cfg.setProperty( Environment.ENABLE_LAZY_LOAD_NO_TRANS, "true" );
|
||||
cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "false" );
|
||||
super.prepare( cfg );
|
||||
|
||||
try ( Session s = getFactory().openSession() ) {
|
||||
s.beginTransaction();
|
||||
|
||||
s.persist( new Person( 1L, "Sam" ) );
|
||||
s.getTransaction().commit();
|
||||
}
|
||||
}
|
||||
|
||||
public void execute() {
|
||||
try ( Session s = getFactory().openSession() ) {
|
||||
s.beginTransaction();
|
||||
Person entity = s.find( Person.class, 1L );
|
||||
entity.name = "Jhon";
|
||||
try {
|
||||
s.merge( entity );
|
||||
s.getTransaction().commit();
|
||||
} catch ( RuntimeException e ) {
|
||||
Assert.fail( "Enhanced entity can't be refreshed: " + e.getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void cleanup() {
|
||||
}
|
||||
|
||||
@Entity
|
||||
public static class Person {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
@Column( name = "name", length = 10, nullable = false )
|
||||
private String name;
|
||||
|
||||
@OneToMany( fetch = FetchType.LAZY, mappedBy = "parent", orphanRemoval = true, cascade = CascadeType.ALL )
|
||||
private List<PersonAddress> details = new ArrayList<>();
|
||||
|
||||
protected Person() {
|
||||
}
|
||||
|
||||
public Person(Long id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
@Entity
|
||||
public static class PersonAddress {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
@ManyToOne( optional = false, fetch = FetchType.LAZY )
|
||||
private Person parent;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* 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.bytecode.enhancement.merge;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.test.bytecode.enhancement.AbstractEnhancerTestTask;
|
||||
import org.junit.Assert;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Luis Barreiro
|
||||
*/
|
||||
public class RefreshEnhancedEntityTestTask extends AbstractEnhancerTestTask {
|
||||
|
||||
private long entityId;
|
||||
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[]{Person.class, PersonAddress.class};
|
||||
}
|
||||
|
||||
public void prepare() {
|
||||
Configuration cfg = new Configuration();
|
||||
cfg.setProperty( Environment.ENABLE_LAZY_LOAD_NO_TRANS, "true" );
|
||||
cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "false" );
|
||||
super.prepare( cfg );
|
||||
|
||||
try ( Session s = getFactory().openSession() ) {
|
||||
s.beginTransaction();
|
||||
|
||||
s.persist( new Person( 1L, "Sam" ) );
|
||||
s.getTransaction().commit();
|
||||
}
|
||||
}
|
||||
|
||||
public void execute() {
|
||||
try ( Session s = getFactory().openSession() ) {
|
||||
s.beginTransaction();
|
||||
Person entity = s.find( Person.class, 1L );
|
||||
entity.name = "Jhon";
|
||||
try {
|
||||
s.refresh( entity );
|
||||
s.getTransaction().commit();
|
||||
} catch ( RuntimeException e ) {
|
||||
Assert.fail( "Enhanced entity can't be refreshed: " + e.getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void cleanup() {
|
||||
}
|
||||
|
||||
@Entity
|
||||
public static class Person {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
@Column( name = "name", length = 10, nullable = false )
|
||||
private String name;
|
||||
|
||||
@OneToMany( fetch = FetchType.LAZY, mappedBy = "parent", orphanRemoval = true, cascade = CascadeType.ALL )
|
||||
private List<PersonAddress> details = new ArrayList<>();
|
||||
|
||||
protected Person() {
|
||||
}
|
||||
|
||||
public Person(Long id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
@Entity
|
||||
public static class PersonAddress {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
@ManyToOne( optional = false, fetch = FetchType.LAZY )
|
||||
private Person parent;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue