Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.proxy.LazyInitializer;

import org.jboss.logging.Logger;

import static jakarta.persistence.spi.LoadState.NOT_LOADED;
import static org.hibernate.engine.internal.ManagedTypeHelper.asManagedEntity;
import static org.hibernate.engine.internal.ManagedTypeHelper.isManagedEntity;
Expand All @@ -30,7 +28,6 @@
* @author Steve Ebersole
*/
public class PersistenceUnitUtilImpl implements PersistenceUnitUtil, Serializable {
private static final Logger log = Logger.getLogger( PersistenceUnitUtilImpl.class );

private final SessionFactoryImplementor sessionFactory;
private final transient PersistenceUtilHelper.MetadataCache cache = new PersistenceUtilHelper.MetadataCache();
Expand All @@ -41,16 +38,11 @@ public PersistenceUnitUtilImpl(SessionFactoryImplementor sessionFactory) {

@Override
public boolean isLoaded(Object entity, String attributeName) {
// added log message to help with HHH-7454, if state == LoadState,NOT_LOADED, returning true or false is not accurate.
log.debug( "PersistenceUnitUtil#isLoaded is not always accurate; consider using EntityManager#contains instead" );
switch ( isLoadedWithoutReference( entity, attributeName, cache ) ) {
case LOADED:
return true;
case NOT_LOADED:
return false;
default:
return isLoadedWithReference( entity, attributeName, cache ) != NOT_LOADED;
}
return switch ( isLoadedWithoutReference( entity, attributeName, cache ) ) {
case LOADED -> true;
case NOT_LOADED -> false;
default -> isLoadedWithReference( entity, attributeName, cache ) != NOT_LOADED;
};
}

@Override
Expand All @@ -60,8 +52,6 @@ public <E> boolean isLoaded(E entity, Attribute<? super E, ?> attribute) {

@Override
public boolean isLoaded(Object entity) {
// added log message to help with HHH-7454, if state == LoadState,NOT_LOADED, returning true or false is not accurate.
log.debug( "PersistenceUnitUtil#isLoaded is not always accurate; consider using EntityManager#contains instead" );
return getLoadState( entity ) != NOT_LOADED;
}

Expand Down Expand Up @@ -106,17 +96,10 @@ else if ( isManagedEntity( entity ) ) {
return entityEntry.getId();
}
else {
// HHH-11426 - best effort to deal with the case of detached entities
log.debug( "jakarta.persistence.PersistenceUnitUtil.getIdentifier may not be able to read identifier of a detached entity" );
return getIdentifierFromPersister( entity );
}
}
else {
log.debug(
"jakarta.persistence.PersistenceUnitUtil.getIdentifier is only intended to work with enhanced entities " +
"(although Hibernate also adapts this support to its proxies); " +
"however the passed entity was not enhanced (nor a proxy).. may not be able to read identifier"
);
return getIdentifierFromPersister( entity );
}
}
Expand Down
Loading