Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

three minor things #9892

Merged
merged 3 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
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 @@ -11,11 +11,12 @@

import org.hibernate.AssertionFailure;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.type.Type;

import org.checkerframework.checker.nullness.qual.Nullable;

import static org.hibernate.pretty.MessageHelper.infoString;

/**
* Uniquely identifies of an entity instance in a particular Session by identifier.
* Note that it's only safe to be used within the scope of a Session: it doesn't consider for example the tenantId
Expand Down Expand Up @@ -117,7 +118,7 @@ public int hashCode() {

@Override
public String toString() {
return "EntityKey" + MessageHelper.infoString( this.persister, identifier, persister.getFactory() );
return "EntityKey" + infoString( this.persister, identifier, persister.getFactory() );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public String guessEntityName(Object entity) throws HibernateException {
return delegate.guessEntityName( entity );
}

@Override
@Override @Deprecated
public Object instantiate(String entityName, Object id) throws HibernateException {
return delegate.instantiate( entityName, id );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,10 @@ default String bestGuessEntityName(Object object, EntityEntry entry) {

/**
* Instantiate the entity class, initializing with the given identifier.
*
* @deprecated No longer used, replaced by {@link #instantiate(EntityPersister, Object)}
*/
@Deprecated(since = "7", forRemoval = true)
Object instantiate(String entityName, Object id) throws HibernateException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ public String guessEntityName(Object entity) throws HibernateException {
return delegate.guessEntityName( entity );
}

@Override
@Override @Deprecated
public Object instantiate(String entityName, Object id) throws HibernateException {
return delegate.instantiate( entityName, id );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1524,7 +1524,7 @@ public void forceFlush(EntityKey key) {
doFlush();
}

@Override
@Override @Deprecated
public Object instantiate(String entityName, Object id) {
return instantiate( requireEntityPersister( entityName ), id );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ public void initializeCollection(PersistentCollection<?> collection, boolean wri
}
}

@Override
@Override @Deprecated
public Object instantiate(String entityName, Object id) {
return instantiate( requireEntityPersister( entityName ), id );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,15 @@ public static String infoString(
info.append( " with null id" );
}
else {
info.append( " with id '" ).append( id ).append( "'" );
info.append( " with id '" );
if ( idType == null ) {
info.append( id );
}
else if ( factory != null ) {
info.append( idType.toLoggableString( id, factory ) );
}
else {
if ( factory != null ) {
info.append( idType.toLoggableString( id, factory ) );
}
else {
info.append( "<not loggable>" );
}
info.append( "<not loggable>" );
}
info.append( "'" );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,40 @@ public void testBatchEntityLoadThenModify(SessionFactoryScope scope) {
);
}

@Test
@JiraKey("HHH-11147")
public void testBatchEntityRemoval(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
final Statistics statistics = scope.getSessionFactory().getStatistics();
statistics.clear();

List<Employer> employers = new ArrayList<>();
for ( int i = 0 ; i < 5 ; i++ ) {
employers.add( session.getReference( Employer.class, i + 1) );
}

assertEquals( 0, statistics.getPrepareStatementCount() );

session.find( Employer.class, 0 );
session.find( Employer.class, 1 );
session.find( Employer.class, 2 );
session.find( Employer.class, 5 );

assertEquals( 1, statistics.getPrepareStatementCount() );

session.find( Employer.class, 6 );
session.find( Employer.class, 7 );

assertEquals( 3, statistics.getPrepareStatementCount() );

for ( Employer employer : employers ) {
assertTrue( Hibernate.isInitialized( employer ) );
}
}
);
}

@BeforeEach
public void setUpData(SessionFactoryScope scope) {
scope.inTransaction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.NaturalId;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;

Expand Down Expand Up @@ -80,7 +81,7 @@ public static class Department {
private Long id;

@OneToMany(mappedBy = "department")
//@BatchSize(size = 5)
@BatchSize(size = 5)
private List<Employee> employees = new ArrayList<>();

//Getters and setters omitted for brevity
Expand Down
Loading