HHH-8559 - Bytecode enhancemer: add test for HHH-3949

Conflicts:
	hibernate-core/src/main/java/org/hibernate/tuple/entity/PojoEntityTuplizer.java
This commit is contained in:
barreiro 2015-06-05 05:11:23 +01:00 committed by Steve Ebersole
parent 44a02e5efc
commit d5ed3a87c4
8 changed files with 264 additions and 0 deletions

View File

@ -6,12 +6,17 @@
*/
package org.hibernate.test.bytecode.enhancement;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.test.bytecode.enhancement.association.ManyToManyAssociationTestTask;
import org.hibernate.test.bytecode.enhancement.association.OneToManyAssociationTestTask;
import org.hibernate.test.bytecode.enhancement.association.OneToOneAssociationTestTask;
import org.hibernate.test.bytecode.enhancement.basic.BasicEnhancementTestTask;
import org.hibernate.test.bytecode.enhancement.dirty.DirtyTrackingTestTask;
import org.hibernate.test.bytecode.enhancement.join.HHH3949TestTask1;
import org.hibernate.test.bytecode.enhancement.join.HHH3949TestTask2;
import org.hibernate.test.bytecode.enhancement.join.HHH3949TestTask3;
import org.hibernate.test.bytecode.enhancement.join.HHH3949TestTask4;
import org.hibernate.test.bytecode.enhancement.lazy.LazyLoadingIntegrationTestTask;
import org.hibernate.test.bytecode.enhancement.lazy.LazyLoadingTestTask;
import org.junit.Test;
@ -44,4 +49,13 @@ public class EnhancerTest extends BaseUnitTestCase {
EnhancerTestUtils.runEnhancerTestTask( LazyLoadingIntegrationTestTask.class );
}
@Test
@TestForIssue( jiraKey = "HHH-3949" )
public void testHHH3949() {
EnhancerTestUtils.runEnhancerTestTask( HHH3949TestTask1.class );
EnhancerTestUtils.runEnhancerTestTask( HHH3949TestTask2.class );
EnhancerTestUtils.runEnhancerTestTask( HHH3949TestTask3.class );
EnhancerTestUtils.runEnhancerTestTask( HHH3949TestTask4.class );
}
}

View File

@ -0,0 +1,52 @@
package org.hibernate.test.bytecode.enhancement.join;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.test.bytecode.enhancement.AbstractEnhancerTestTask;
public abstract class AbstractHHH3949TestTask extends AbstractEnhancerTestTask {
public Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {Person.class, Vehicle.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 );
Session session = getFactory().openSession();
Transaction tx = session.beginTransaction();
Person person1 = new Person( "Johnny" );
Person person2 = new Person( "Ricky" );
Person person3 = new Person( "Rosy" );
session.save( person1 );
session.save( person2 );
session.save( person3 );
Vehicle vehicle1 = new Vehicle( "Volkswagen Golf" );
vehicle1.setDriver( person1 );
session.save( vehicle1 );
Vehicle vehicle2 = new Vehicle( "Subaru Impreza" );
vehicle2.setDriver( person2 );
person2.setVehicle( vehicle2 );
session.save( vehicle2 );
Vehicle vehicle3 = new Vehicle( "Renault Truck" );
session.save( vehicle3 );
tx.commit();
session.close();
}
protected void cleanup() {
}
}

View File

@ -0,0 +1,23 @@
package org.hibernate.test.bytecode.enhancement.join;
import java.util.List;
import org.hibernate.Session;
import org.junit.Assert;
public class HHH3949TestTask1 extends AbstractHHH3949TestTask {
@SuppressWarnings("unchecked")
public void execute() {
Session session = getFactory().openSession();
List<Person> persons = (List<Person>) session.createQuery( "from Person p left join fetch p.vehicle" ).list();
for ( Person person : persons ) {
if ( person.getId() < 3 ) {
Assert.assertNotNull( person.getVehicle() );
Assert.assertNotNull( person.getVehicle().getDriver() );
}
}
session.close();
}
}

View File

@ -0,0 +1,24 @@
package org.hibernate.test.bytecode.enhancement.join;
import java.util.List;
import org.hibernate.Session;
import org.junit.Assert;
public class HHH3949TestTask2 extends AbstractHHH3949TestTask {
@SuppressWarnings("unchecked")
public void execute() {
Session session = getFactory().openSession();
List<Vehicle> vehicles = (List<Vehicle>) session.createQuery( "from Vehicle v left join fetch v.driver" )
.list();
for ( Vehicle vehicle : vehicles ) {
if ( vehicle.getId() < 3 ) {
Assert.assertNotNull( vehicle.getDriver() );
Assert.assertNotNull( vehicle.getDriver().getVehicle() );
}
}
session.close();
}
}

View File

@ -0,0 +1,27 @@
package org.hibernate.test.bytecode.enhancement.join;
import java.util.List;
import org.hibernate.FetchMode;
import org.hibernate.Session;
import org.junit.Assert;
public class HHH3949TestTask3 extends AbstractHHH3949TestTask {
@SuppressWarnings("unchecked")
public void execute() {
Session session = getFactory().openSession();
List<Person> persons = (List<Person>) session.createCriteria( Person.class ).setFetchMode(
"vehicle",
FetchMode.JOIN
).list();
for ( Person person : persons ) {
if ( person.getId() < 3 ) {
Assert.assertNotNull( person.getVehicle() );
Assert.assertNotNull( person.getVehicle().getDriver() );
}
}
session.close();
}
}

View File

@ -0,0 +1,28 @@
package org.hibernate.test.bytecode.enhancement.join;
import java.util.List;
import org.hibernate.FetchMode;
import org.hibernate.Session;
import org.junit.Assert;
public class HHH3949TestTask4 extends AbstractHHH3949TestTask {
@SuppressWarnings("unchecked")
public void execute() {
Session session = getFactory().openSession();
List<Vehicle> vehicles = (List<Vehicle>) session.createCriteria( Vehicle.class ).setFetchMode(
"driver",
FetchMode.JOIN
).list();
for ( Vehicle vehicle : vehicles ) {
if ( vehicle.getId() < 3 ) {
Assert.assertNotNull( vehicle.getDriver() );
Assert.assertNotNull( vehicle.getDriver().getVehicle() );
}
}
session.close();
}
}

View File

@ -0,0 +1,47 @@
package org.hibernate.test.bytecode.enhancement.join;
import java.io.Serializable;
import javax.persistence.*;
import org.hibernate.annotations.LazyToOne;
import org.hibernate.annotations.LazyToOneOption;
@Entity
public class Person implements Serializable {
@Id
@GeneratedValue
private Integer id;
private String name;
@OneToOne(optional = true, mappedBy = "driver", fetch = FetchType.LAZY)
@LazyToOne(LazyToOneOption.NO_PROXY)
private Vehicle vehicle;
public Vehicle getVehicle() {
return vehicle;
}
public void setVehicle(Vehicle vehicle) {
this.vehicle = vehicle;
}
public Integer getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Person() {
}
public Person(String name) {
this.name = name;
}
}

View File

@ -0,0 +1,49 @@
package org.hibernate.test.bytecode.enhancement.join;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToOne;
@Entity
public class Vehicle implements Serializable {
@Id
@GeneratedValue
private Integer id;
private String name;
@OneToOne(optional = true, fetch = FetchType.LAZY)
private Person driver;
public Integer getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Person getDriver() {
return driver;
}
public void setDriver(Person driver) {
this.driver = driver;
}
public Vehicle() {
}
public Vehicle(String name) {
this.name = name;
}
}