Fix joined sublcass hql wrong join type for associations
This commit is contained in:
parent
b52dfbab7e
commit
531d0f923c
|
@ -592,6 +592,7 @@ public class ToOneAttributeMapping
|
|||
tableGroup = createTableGroupJoin(
|
||||
fetchablePath,
|
||||
true,
|
||||
getJoinType( fetchablePath, parentTableGroup ),
|
||||
lockMode,
|
||||
creationState,
|
||||
parentTableGroup
|
||||
|
@ -737,18 +738,35 @@ public class ToOneAttributeMapping
|
|||
LockMode lockMode,
|
||||
DomainResultCreationState creationState,
|
||||
TableGroup parentTableGroup) {
|
||||
final SqlAstJoinType sqlAstJoinType;
|
||||
return createTableGroupJoin(
|
||||
fetchablePath,
|
||||
fetched,
|
||||
getDefaultSqlAstJoinType( parentTableGroup ),
|
||||
lockMode,
|
||||
creationState,
|
||||
parentTableGroup
|
||||
);
|
||||
}
|
||||
|
||||
private SqlAstJoinType getDefaultSqlAstJoinType(TableGroup parentTableGroup) {
|
||||
if ( isNullable ) {
|
||||
sqlAstJoinType = SqlAstJoinType.LEFT;
|
||||
return SqlAstJoinType.LEFT;
|
||||
}
|
||||
else if ( parentTableGroup.getModelPart() instanceof CollectionPart ) {
|
||||
sqlAstJoinType = SqlAstJoinType.LEFT;
|
||||
return SqlAstJoinType.LEFT;
|
||||
}
|
||||
else {
|
||||
sqlAstJoinType = SqlAstJoinType.INNER;
|
||||
return SqlAstJoinType.INNER;
|
||||
}
|
||||
}
|
||||
|
||||
private TableGroup createTableGroupJoin(
|
||||
NavigablePath fetchablePath,
|
||||
boolean fetched,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
LockMode lockMode,
|
||||
DomainResultCreationState creationState,
|
||||
TableGroup parentTableGroup) {
|
||||
final TableGroupJoin tableGroupJoin = createTableGroupJoin(
|
||||
fetchablePath,
|
||||
parentTableGroup,
|
||||
|
@ -821,8 +839,6 @@ public class ToOneAttributeMapping
|
|||
lhs
|
||||
);
|
||||
|
||||
final TableReference lhsTableReference = lhs.resolveTableReference( navigablePath, identifyingColumnsTableExpression );
|
||||
|
||||
final TableGroupJoin tableGroupJoin = new TableGroupJoin(
|
||||
navigablePath,
|
||||
sqlAstJoinType,
|
||||
|
@ -830,6 +846,8 @@ public class ToOneAttributeMapping
|
|||
null
|
||||
);
|
||||
|
||||
final TableReference lhsTableReference = lhs.resolveTableReference( navigablePath, identifyingColumnsTableExpression );
|
||||
|
||||
lazyTableGroup.setTableGroupInitializerCallback(
|
||||
tableGroup -> tableGroupJoin.applyPredicate(
|
||||
foreignKeyDescriptor.generateJoinPredicate(
|
||||
|
@ -851,6 +869,15 @@ public class ToOneAttributeMapping
|
|||
return tableGroupJoin;
|
||||
}
|
||||
|
||||
private SqlAstJoinType getJoinType(NavigablePath navigablePath, TableGroup tableGroup) {
|
||||
for ( TableGroupJoin tableGroupJoin : tableGroup.getTableGroupJoins() ) {
|
||||
if ( tableGroupJoin.getNavigablePath().equals( navigablePath ) ) {
|
||||
return tableGroupJoin.getJoinType();
|
||||
}
|
||||
}
|
||||
return getDefaultSqlAstJoinType( tableGroup );
|
||||
}
|
||||
|
||||
public TableGroup createTableGroupJoinInternal(
|
||||
NavigablePath navigablePath,
|
||||
boolean fetched,
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Address.java 9914 2006-05-09 09:37:18Z max.andersen@jboss.com $
|
||||
package org.hibernate.test.onetoone.joined;
|
||||
package org.hibernate.orm.test.onetoone.joined;
|
||||
|
||||
|
||||
/**
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Entity.java 5686 2005-02-12 07:27:32Z steveebersole $
|
||||
package org.hibernate.test.onetoone.joined;
|
||||
package org.hibernate.orm.test.onetoone.joined;
|
||||
|
||||
|
||||
/**
|
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.onetoone.joined;
|
||||
package org.hibernate.orm.test.onetoone.joined;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -28,7 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
|||
* @author Gavin King
|
||||
*/
|
||||
@DomainModel(
|
||||
xmlMappings = "org/hibernate/test/onetoone/joined/Person.hbm.xml"
|
||||
xmlMappings = "org/hibernate/orm/test/onetoone/joined/Person.hbm.xml"
|
||||
)
|
||||
@SessionFactory(
|
||||
generateStatistics = true
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Org.java 5686 2005-02-12 07:27:32Z steveebersole $
|
||||
package org.hibernate.test.onetoone.joined;
|
||||
package org.hibernate.orm.test.onetoone.joined;
|
||||
|
||||
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping
|
||||
package="org.hibernate.test.onetoone.joined"
|
||||
package="org.hibernate.orm.test.onetoone.joined"
|
||||
default-access="field">
|
||||
|
||||
<class name="Entity">
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Person.java 5686 2005-02-12 07:27:32Z steveebersole $
|
||||
package org.hibernate.test.onetoone.joined;
|
||||
package org.hibernate.orm.test.onetoone.joined;
|
||||
|
||||
|
||||
/**
|
|
@ -1380,7 +1380,7 @@ public class HQLTest extends QueryTranslatorTestCase {
|
|||
@Test
|
||||
public void testOneToOneJoinedFetch() throws Exception {
|
||||
// From OneToOneTest.testOneToOneOnSubclass
|
||||
assertTranslation( "from org.hibernate.test.onetoone.joined.Person p join fetch p.address left join fetch p.mailingAddress" );
|
||||
assertTranslation( "from org.hibernate.orm.test.onetoone.joined.Person p join fetch p.address left join fetch p.mailingAddress" );
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue