use of org.hibernate.loader.ast.internal.SingleIdEntityLoaderStandardImpl in project hibernate-orm by hibernate.
the class LoadPlanBuilderTest method testCascadeBasedBuild.
@Test
public void testCascadeBasedBuild(SessionFactoryScope scope) {
final SessionFactoryImplementor sessionFactory = scope.getSessionFactory();
final EntityPersister entityDescriptor = (EntityPersister) sessionFactory.getRuntimeMetamodels().getEntityMappingType(Message.class);
final SingleIdEntityLoaderStandardImpl<?> loader = new SingleIdEntityLoaderStandardImpl<>(entityDescriptor, sessionFactory);
final LoadQueryInfluencers influencers = new LoadQueryInfluencers() {
@Override
public CascadingFetchProfile getEnabledCascadingFetchProfile() {
return CascadingFetchProfile.MERGE;
}
};
final SingleIdLoadPlan<?> loadPlan = loader.resolveLoadPlan(LockOptions.READ, influencers, sessionFactory);
final List<DomainResult<?>> domainResults = loadPlan.getJdbcSelect().getJdbcValuesMappingProducer().resolve(null, sessionFactory).getDomainResults();
assertThat(domainResults).hasSize(1);
final DomainResult<?> domainResult = domainResults.get(0);
assertThat(domainResult).isInstanceOf(EntityResult.class);
final EntityResult entityResult = (EntityResult) domainResult;
assertThat(entityResult.getFetches()).hasSize(2);
final Fetch txtFetch = entityResult.getFetches().get(0);
assertThat(txtFetch).isNotNull();
assertThat(txtFetch.getFetchedMapping().getFetchableName()).isEqualTo("msgTxt");
assertThat(txtFetch.getTiming()).isEqualTo(FetchTiming.IMMEDIATE);
final Fetch posterFetch = entityResult.getFetches().get(1);
assertThat(posterFetch).isNotNull();
assertThat(posterFetch.getFetchedMapping().getFetchableName()).isEqualTo("poster");
assertThat(posterFetch.getTiming()).isEqualTo(FetchTiming.IMMEDIATE);
}
use of org.hibernate.loader.ast.internal.SingleIdEntityLoaderStandardImpl in project hibernate-orm by hibernate.
the class LoadingSmokeTests method testBasicGet.
@Test
public void testBasicGet(SessionFactoryScope scope) {
scope.inTransaction(session -> {
final BasicEntity gotten = session.byId(BasicEntity.class).load(1);
assertThat(gotten, notNullValue());
assertThat(Hibernate.isInitialized(gotten), is(true));
assertThat(gotten.getId(), is(1));
assertThat(gotten.getData(), is("first"));
final AbstractEntityPersister entityDescriptor = (AbstractEntityPersister) session.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor(BasicEntity.class);
final SingleIdEntityLoader singleIdEntityLoader = entityDescriptor.getSingleIdEntityLoader();
assertThat(singleIdEntityLoader, instanceOf(SingleIdEntityLoaderStandardImpl.class));
assertThat(((SingleIdEntityLoaderStandardImpl) singleIdEntityLoader).getNonReusablePlansGenerated().get(), is(0));
});
}
use of org.hibernate.loader.ast.internal.SingleIdEntityLoaderStandardImpl in project hibernate-orm by hibernate.
the class LoadPlanBuilderTest method testSimpleBuild.
@Test
public void testSimpleBuild(SessionFactoryScope scope) {
final SessionFactoryImplementor sessionFactory = scope.getSessionFactory();
final EntityPersister entityDescriptor = sessionFactory.getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor(Message.class);
final SingleIdEntityLoaderStandardImpl<?> loader = new SingleIdEntityLoaderStandardImpl<>(entityDescriptor, sessionFactory);
final SingleIdLoadPlan<?> loadPlan = loader.resolveLoadPlan(LockOptions.READ, LoadQueryInfluencers.NONE, sessionFactory);
final List<DomainResult<?>> domainResults = loadPlan.getJdbcSelect().getJdbcValuesMappingProducer().resolve(null, sessionFactory).getDomainResults();
assertThat(domainResults).hasSize(1);
final DomainResult<?> domainResult = domainResults.get(0);
assertThat(domainResult).isInstanceOf(EntityResult.class);
final EntityResult entityResult = (EntityResult) domainResult;
assertThat(entityResult.getFetches()).hasSize(2);
final Fetch txtFetch = entityResult.getFetches().get(0);
assertThat(txtFetch).isNotNull();
assertThat(txtFetch.getFetchedMapping().getFetchableName()).isEqualTo("msgTxt");
assertThat(txtFetch.getTiming()).isEqualTo(FetchTiming.IMMEDIATE);
final Fetch posterFetch = entityResult.getFetches().get(1);
assertThat(posterFetch).isNotNull();
assertThat(posterFetch.getFetchedMapping().getFetchableName()).isEqualTo("poster");
assertThat(posterFetch.getTiming()).isEqualTo(FetchTiming.DELAYED);
}
Aggregations