Fixup review comments

This commit is contained in:
Christian Beikov 2021-12-02 12:29:19 +01:00
parent 9392b94ee7
commit 47416b9e24
3 changed files with 31 additions and 9 deletions

View File

@ -19,6 +19,7 @@ import org.hibernate.dialect.OracleDialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.loader.NonUniqueDiscoveredSqlAliasException;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.transform.Transformers;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.userguide.model.AddressType;
@ -41,6 +42,7 @@ import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
@ -762,6 +764,10 @@ public class SQLTest extends BaseEntityManagerFunctionalTestCase {
}
//end::sql-jpa-composite-key-entity-associations_named-query-example[]
assertEquals(1, tuples.size());
SpaceShip spaceShip = (SpaceShip) tuples.get( 0 )[0];
assertNotNull( spaceShip.getCaptain() );
assertTrue( spaceShip.getCaptain() instanceof HibernateProxy );
assertTrue( ( (HibernateProxy) spaceShip.getCaptain() ).getHibernateLazyInitializer().isUninitialized() );
});
}

View File

@ -342,7 +342,7 @@ public class DomainResultCreationStateImpl
final Map.Entry<String, NavigablePath> oldEntry = relativePathStack.getCurrent();
final String key = oldEntry.getKey();
currentEntry = new AbstractMap.SimpleEntry<>(
getRelativePath( !key.isEmpty() ? key : "", fetchable, fetchableContainer ),
getRelativePath( key, fetchable, fetchableContainer ),
oldEntry.getValue().append( fetchableName )
);
}
@ -351,6 +351,18 @@ public class DomainResultCreationStateImpl
FetchBuilder explicitFetchBuilder = fetchBuilderResolverStack
.getCurrent()
.apply( fullPath );
DynamicFetchBuilderLegacy fetchBuilderLegacy;
if ( explicitFetchBuilder == null ) {
fetchBuilderLegacy = legacyFetchResolver.resolve(
fromClauseAccess.findTableGroup( fetchParent.getNavigablePath() )
.getPrimaryTableReference()
.getIdentificationVariable(),
fetchableName
);
}
else {
fetchBuilderLegacy = null;
}
if ( fetchable instanceof Association && fetchable.getMappedFetchOptions().getTiming() == FetchTiming.DELAYED ) {
final Association association = (Association) fetchable;
final ForeignKeyDescriptor foreignKeyDescriptor = association.getForeignKeyDescriptor();
@ -358,7 +370,8 @@ public class DomainResultCreationStateImpl
final String partName = attributeName( foreignKeyDescriptor.getSide( association.getSideNature().inverse() )
.getModelPart());
if ( explicitFetchBuilder == null && partName != null ) {
// If there are no fetch builders for this association, we only want to fetch the FK
if ( explicitFetchBuilder == null && fetchBuilderLegacy == null && partName != null ) {
currentEntry = new AbstractMap.SimpleEntry<>(
currentEntry.getKey() + "." + partName,
currentEntry.getValue().append( partName )
@ -366,6 +379,14 @@ public class DomainResultCreationStateImpl
explicitFetchBuilder = fetchBuilderResolverStack
.getCurrent()
.apply( currentEntry.getKey() );
if ( explicitFetchBuilder == null ) {
fetchBuilderLegacy = legacyFetchResolver.resolve(
fromClauseAccess.findTableGroup( fetchParent.getNavigablePath() )
.getPrimaryTableReference()
.getIdentificationVariable(),
fetchableName
);
}
}
}
relativePathStack.push( currentEntry );
@ -377,12 +398,6 @@ public class DomainResultCreationStateImpl
fetchBuilder = explicitFetchBuilder;
}
else {
final DynamicFetchBuilderLegacy fetchBuilderLegacy = legacyFetchResolver.resolve(
fromClauseAccess.findTableGroup( fetchParent.getNavigablePath() )
.getPrimaryTableReference()
.getIdentificationVariable(),
fetchableName
);
if ( fetchBuilderLegacy == null ) {
fetchBuilder = Builders.implicitFetchBuilder( fetchPath, fetchable, this );
}

View File

@ -9,6 +9,7 @@ package org.hibernate.orm.test.envers.integration.reventity;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import jakarta.persistence.EntityManager;
@ -60,7 +61,7 @@ public class LocalDateTimeTest extends BaseEnversJPAFunctionalTestCase {
em.persist( entity );
em.getTransaction().commit();
timestampEnd = Instant.now();
timestampEnd = Instant.now().plus( 1L, ChronoUnit.SECONDS );
}
catch( InterruptedException x ) {
fail( "Unexpected interrupted exception" );