HHH-18535 - Support jakarta.persistence.EntityResult#lockMode
This commit is contained in:
parent
e574f88fd6
commit
80b12c46e7
|
@ -46,6 +46,7 @@ import jakarta.persistence.ColumnResult;
|
||||||
import jakarta.persistence.ConstructorResult;
|
import jakarta.persistence.ConstructorResult;
|
||||||
import jakarta.persistence.EntityResult;
|
import jakarta.persistence.EntityResult;
|
||||||
import jakarta.persistence.FieldResult;
|
import jakarta.persistence.FieldResult;
|
||||||
|
import jakarta.persistence.LockModeType;
|
||||||
import jakarta.persistence.SqlResultSetMapping;
|
import jakarta.persistence.SqlResultSetMapping;
|
||||||
|
|
||||||
import static org.hibernate.internal.util.collections.CollectionHelper.arrayList;
|
import static org.hibernate.internal.util.collections.CollectionHelper.arrayList;
|
||||||
|
@ -231,6 +232,7 @@ public class SqlResultSetMappingDescriptor implements NamedResultSetMappingDescr
|
||||||
private final NavigablePath navigablePath;
|
private final NavigablePath navigablePath;
|
||||||
private final String entityName;
|
private final String entityName;
|
||||||
private final String discriminatorColumn;
|
private final String discriminatorColumn;
|
||||||
|
private final LockModeType lockMode;
|
||||||
|
|
||||||
private final Map<String, AttributeFetchDescriptor> explicitFetchMappings;
|
private final Map<String, AttributeFetchDescriptor> explicitFetchMappings;
|
||||||
|
|
||||||
|
@ -239,6 +241,7 @@ public class SqlResultSetMappingDescriptor implements NamedResultSetMappingDescr
|
||||||
this.navigablePath = new NavigablePath( entityName );
|
this.navigablePath = new NavigablePath( entityName );
|
||||||
|
|
||||||
this.discriminatorColumn = entityResult.discriminatorColumn();
|
this.discriminatorColumn = entityResult.discriminatorColumn();
|
||||||
|
this.lockMode = entityResult.lockMode();
|
||||||
|
|
||||||
this.explicitFetchMappings = extractFetchMappings( navigablePath, entityResult );
|
this.explicitFetchMappings = extractFetchMappings( navigablePath, entityResult );
|
||||||
}
|
}
|
||||||
|
@ -288,7 +291,9 @@ public class SqlResultSetMappingDescriptor implements NamedResultSetMappingDescr
|
||||||
|
|
||||||
return new ResultMementoEntityJpa(
|
return new ResultMementoEntityJpa(
|
||||||
entityDescriptor,
|
entityDescriptor,
|
||||||
LockMode.READ,
|
lockMode == LockModeType.OPTIMISTIC
|
||||||
|
? LockMode.NONE
|
||||||
|
: LockMode.fromJpaLockMode( lockMode ),
|
||||||
discriminatorMemento,
|
discriminatorMemento,
|
||||||
fetchMementos
|
fetchMementos
|
||||||
);
|
);
|
||||||
|
|
|
@ -21,6 +21,7 @@ import org.hibernate.query.results.ResultBuilder;
|
||||||
import org.hibernate.query.results.ResultsHelper;
|
import org.hibernate.query.results.ResultsHelper;
|
||||||
import org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy;
|
import org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy;
|
||||||
import org.hibernate.spi.NavigablePath;
|
import org.hibernate.spi.NavigablePath;
|
||||||
|
import org.hibernate.sql.ast.spi.SqlAliasBase;
|
||||||
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
||||||
import org.hibernate.sql.results.graph.entity.EntityResult;
|
import org.hibernate.sql.results.graph.entity.EntityResult;
|
||||||
import org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata;
|
import org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata;
|
||||||
|
@ -90,6 +91,9 @@ public class CompleteResultBuilderEntityJpa implements CompleteResultBuilderEnti
|
||||||
int resultPosition,
|
int resultPosition,
|
||||||
BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver,
|
BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver,
|
||||||
DomainResultCreationState domainResultCreationState) {
|
DomainResultCreationState domainResultCreationState) {
|
||||||
|
final String implicitAlias = entityDescriptor.getSqlAliasStem() + resultPosition;
|
||||||
|
final SqlAliasBase sqlAliasBase = domainResultCreationState.getSqlAliasBaseManager().createSqlAliasBase( implicitAlias );
|
||||||
|
|
||||||
final DomainResultCreationStateImpl impl = ResultsHelper.impl( domainResultCreationState );
|
final DomainResultCreationStateImpl impl = ResultsHelper.impl( domainResultCreationState );
|
||||||
impl.disallowPositionalSelections();
|
impl.disallowPositionalSelections();
|
||||||
|
|
||||||
|
@ -103,8 +107,8 @@ public class CompleteResultBuilderEntityJpa implements CompleteResultBuilderEnti
|
||||||
// since this is only used for result set mappings, the canUseInnerJoins value is irrelevant.
|
// since this is only used for result set mappings, the canUseInnerJoins value is irrelevant.
|
||||||
true,
|
true,
|
||||||
navigablePath,
|
navigablePath,
|
||||||
null,
|
implicitAlias,
|
||||||
null,
|
sqlAliasBase,
|
||||||
null,
|
null,
|
||||||
impl.getSqlAstCreationState()
|
impl.getSqlAstCreationState()
|
||||||
)
|
)
|
||||||
|
@ -113,7 +117,7 @@ public class CompleteResultBuilderEntityJpa implements CompleteResultBuilderEnti
|
||||||
return new EntityResultImpl(
|
return new EntityResultImpl(
|
||||||
navigablePath,
|
navigablePath,
|
||||||
entityDescriptor,
|
entityDescriptor,
|
||||||
null,
|
implicitAlias,
|
||||||
lockMode,
|
lockMode,
|
||||||
(entityResult) -> {
|
(entityResult) -> {
|
||||||
if ( discriminatorFetchBuilder == null ) {
|
if ( discriminatorFetchBuilder == null ) {
|
||||||
|
|
|
@ -19,12 +19,14 @@ import java.util.Set;
|
||||||
|
|
||||||
import jakarta.persistence.LockModeType;
|
import jakarta.persistence.LockModeType;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
|
import org.hibernate.dialect.H2Dialect;
|
||||||
import org.hibernate.query.named.NamedResultSetMappingMemento;
|
import org.hibernate.query.named.NamedResultSetMappingMemento;
|
||||||
|
|
||||||
import org.hibernate.testing.orm.domain.gambit.EntityOfBasics;
|
import org.hibernate.testing.orm.domain.gambit.EntityOfBasics;
|
||||||
import org.hibernate.testing.orm.junit.DomainModel;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
import org.hibernate.testing.orm.junit.FailureExpected;
|
import org.hibernate.testing.orm.junit.FailureExpected;
|
||||||
import org.hibernate.testing.orm.junit.Jira;
|
import org.hibernate.testing.orm.junit.Jira;
|
||||||
|
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
import org.hibernate.testing.orm.junit.Setting;
|
import org.hibernate.testing.orm.junit.Setting;
|
||||||
|
@ -123,8 +125,10 @@ public class EntityResultTests extends AbstractUsageTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@FailureExpected( jiraKey = "HHH-18535", reason = "Support for @EntityResult(lockMode) not implemented yet")
|
@RequiresDialect(
|
||||||
@Jira( "https://hibernate.atlassian.net/browse/HHH-18535" )
|
value = H2Dialect.class,
|
||||||
|
comment = "We don't really care about the execution on the database, just how the result-set is handled. Some databases (mssql) don't like this query"
|
||||||
|
)
|
||||||
public void testImplicitAttributeMappingWithLockMode(SessionFactoryScope scope) {
|
public void testImplicitAttributeMappingWithLockMode(SessionFactoryScope scope) {
|
||||||
scope.inTransaction(
|
scope.inTransaction(
|
||||||
session -> {
|
session -> {
|
||||||
|
|
Loading…
Reference in New Issue