HHH-11108 - Add test to prove that @Basic( fetch = FetchType.LAZY ) really works as expected

Roll back changes since we already have the JpaRuntimeEnhancementTest to prove this works and it does not use build-time enhancement
This commit is contained in:
Vlad Mihalcea 2016-09-22 12:40:22 +03:00
parent f521017b90
commit dda90ef3d0
2 changed files with 0 additions and 106 deletions

View File

@ -30,18 +30,6 @@ apply plugin: 'hibernate-matrix-testing'
apply from: "${rootProject.projectDir}/utilities.gradle" apply from: "${rootProject.projectDir}/utilities.gradle"
apply plugin: 'org.hibernate.orm'
// Java 9 ftw!
if ( !JavaVersion.current().isJava9Compatible() ) {
hibernate {
enhance {
enableLazyInitialization = true
}
}
}
defaultTasks 'buildDocs' defaultTasks 'buildDocs'
configurations { configurations {
@ -120,17 +108,6 @@ dependencies {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} }
if ( JavaVersion.current().isJava9Compatible() ) {
logger.warn( '[WARN] Skipping Javassist-related tests for hibernate-core due to Javassist JDK 9 incompatibility' )
// we need to exclude tests using Javassist enhancement, which does not properly support
// Java 9 yet - https://issues.jboss.org/browse/JASSIST-261
test {
// rather than wild-cards, keep an explicit list
exclude 'org/hibernate/userguide/fetching/LazyBasicAttributeTest.class'
}
}
processTestResources.doLast( { processTestResources.doLast( {
copy { copy {
from( sourceSets.test.java.srcDirs ) { from( sourceSets.test.java.srcDirs ) {

View File

@ -1,83 +0,0 @@
/*
* 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.userguide.fetching;
import java.sql.PreparedStatement;
import java.util.List;
import java.util.Map;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.userguide.model.Image;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
import org.junit.Test;
import org.jboss.logging.Logger;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* @author Vlad Mihalcea
*/
@RequiresDialect(H2Dialect.class)
public class LazyBasicAttributeTest extends BaseEntityManagerFunctionalTestCase {
private static final Logger LOGGER = Logger.getLogger( LazyBasicAttributeTest.class );
private PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider();
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
Image.class,
};
}
@Override
protected Map buildSettings() {
Map settings = super.buildSettings();
settings.put(
AvailableSettings.CONNECTION_PROVIDER,
connectionProvider
);
return settings;
}
@Override
public void releaseResources() {
super.releaseResources();
connectionProvider.stop();
}
@Test
public void test() {
doInJPA( this::entityManagerFactory, entityManager -> {
Image image = new Image();
image.setId(1L);
image.setContent(new byte[] {1, 2, 3});
entityManager.persist(image);
});
doInJPA( this::entityManagerFactory, entityManager -> {
connectionProvider.clear();
Image image = entityManager.find(Image.class, 1L);
LOGGER.debug("Fetched image");
List<PreparedStatement> preparedStatements = connectionProvider.getPreparedStatements();
assertEquals( 1, preparedStatements.size() );
assertNotNull( connectionProvider.getPreparedStatement( "select image0_.id as id1_0_0_ from Image image0_ where image0_.id=?" ) );
assertArrayEquals(new byte[] {1, 2, 3}, image.getContent());
preparedStatements = connectionProvider.getPreparedStatements();
assertEquals( 2, preparedStatements.size() );
assertNotNull( connectionProvider.getPreparedStatement( "select image_.content as content2_0_ from Image image_ where image_.id=?" ) );
});
}
}