Skip to content

HHH-19565 @SQLRestriction should not be applied to a @ManyToOne #10381

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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 @@ -259,6 +259,7 @@ private static org.hibernate.mapping.ManyToOne handleJoinTable(
notFoundAction,
value
) );
value.markAsJoinTable();
return value;
}
else {
Expand All @@ -270,7 +271,9 @@ private static org.hibernate.mapping.ManyToOne handleJoinTable(
join.disableForeignKeyCreation();
}
// All FK columns should be in the same table
return new org.hibernate.mapping.ManyToOne( context, joinColumns.getTable() );
var manyToOne = new org.hibernate.mapping.ManyToOne( context, joinColumns.getTable() );
manyToOne.markAsJoinTable();
return manyToOne;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.hibernate.ObjectNotFoundException;
import org.hibernate.WrongClassException;
import org.hibernate.annotations.ConcreteProxy;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
Expand All @@ -20,7 +21,6 @@
import org.hibernate.sql.ast.tree.select.SelectStatement;
import org.hibernate.sql.exec.internal.BaseExecutionContext;
import org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl;
import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect;
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
import org.hibernate.sql.exec.spi.JdbcParametersList;
import org.hibernate.sql.results.internal.RowTransformerStandardImpl;
Expand Down Expand Up @@ -60,6 +60,7 @@ public EntityConcreteTypeLoader(EntityMappingType entityDescriptor, SessionFacto

public EntityMappingType getConcreteType(Object id, SharedSessionContractImplementor session) {
final SessionFactoryImplementor factory = session.getSessionFactory();
final JdbcServices jdbcServices = factory.getJdbcServices();

final JdbcParameterBindings bindings = new JdbcParameterBindingsImpl( jdbcParameters.size() );
final int offset = bindings.registerParametersForEachJdbcValue(
Expand All @@ -70,14 +71,12 @@ public EntityMappingType getConcreteType(Object id, SharedSessionContractImpleme
);
assert offset == jdbcParameters.size();

final JdbcOperationQuerySelect jdbcSelect =
factory.getJdbcServices().getJdbcEnvironment().getSqlAstTranslatorFactory()
.buildSelectTranslator( factory, sqlSelect )
.translate( bindings, QueryOptions.NONE );
final List<Object> results =
session.getFactory().getJdbcServices().getJdbcSelectExecutor()
final List<?> results =
jdbcServices.getJdbcSelectExecutor()
.list(
jdbcSelect,
jdbcServices.getJdbcEnvironment().getSqlAstTranslatorFactory()
.buildSelectTranslator( factory, sqlSelect )
.translate( bindings, QueryOptions.NONE ),
bindings,
new BaseExecutionContext( session ),
RowTransformerStandardImpl.instance(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
public final class ManyToOne extends ToOne {
private boolean isLogicalOneToOne;
private boolean hasJoinTable;
private NotFoundAction notFoundAction;

private transient ManyToOneType resolvedType;
Expand Down Expand Up @@ -141,6 +142,14 @@ public boolean isLogicalOneToOne() {
return isLogicalOneToOne;
}

public void markAsJoinTable() {
hasJoinTable = true;
}

public boolean hasJoinTable() {
return hasJoinTable;
}

@Override
public boolean isNullable() {
return getReferencedPropertyName() != null || super.isNullable();
Expand Down
Loading