Move annotations.manytoone tests and fix table reference resolving issues
This commit is contained in:
parent
76f424fcff
commit
e415d1bde6
|
@ -890,14 +890,15 @@ public class ToOneAttributeMapping
|
|||
sqlExpressionResolver,
|
||||
creationContext
|
||||
),
|
||||
np -> {
|
||||
(np, tableExpression) -> {
|
||||
if ( !canUseParentTableGroup ) {
|
||||
return false;
|
||||
}
|
||||
NavigablePath path = np.getParent();
|
||||
// Fast path
|
||||
if ( path != null && navigablePath.equals( path ) ) {
|
||||
return targetKeyPropertyNames.contains( np.getUnaliasedLocalName() );
|
||||
return targetKeyPropertyNames.contains( np.getUnaliasedLocalName() )
|
||||
&& identifyingColumnsTableExpression.equals( tableExpression );
|
||||
}
|
||||
final StringBuilder sb = new StringBuilder( np.getFullPath().length() );
|
||||
sb.append( np.getUnaliasedLocalName() );
|
||||
|
@ -906,9 +907,9 @@ public class ToOneAttributeMapping
|
|||
sb.insert( 0, path.getUnaliasedLocalName() );
|
||||
path = path.getParent();
|
||||
}
|
||||
return path != null && navigablePath.equals( path ) && targetKeyPropertyNames.contains(
|
||||
sb.toString()
|
||||
);
|
||||
return path != null && navigablePath.equals( path )
|
||||
&& targetKeyPropertyNames.contains( sb.toString() )
|
||||
&& identifyingColumnsTableExpression.equals( tableExpression );
|
||||
},
|
||||
this,
|
||||
explicitSourceAlias,
|
||||
|
|
|
@ -9,7 +9,7 @@ package org.hibernate.sql.ast.tree.from;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
|
@ -30,7 +30,7 @@ public class LazyTableGroup extends AbstractColumnReferenceQualifier implements
|
|||
private final SessionFactoryImplementor sessionFactory;
|
||||
private final Supplier<TableGroup> tableGroupSupplier;
|
||||
private final TableGroup parentTableGroup;
|
||||
private final Predicate<NavigablePath> navigablePathChecker;
|
||||
private final BiPredicate<NavigablePath, String> navigablePathChecker;
|
||||
private Consumer<TableGroup> tableGroupConsumer;
|
||||
private TableGroup tableGroup;
|
||||
|
||||
|
@ -38,7 +38,7 @@ public class LazyTableGroup extends AbstractColumnReferenceQualifier implements
|
|||
boolean canUseInnerJoins,
|
||||
NavigablePath navigablePath,
|
||||
Supplier<TableGroup> tableGroupSupplier,
|
||||
Predicate<NavigablePath> navigablePathChecker,
|
||||
BiPredicate<NavigablePath, String> navigablePathChecker,
|
||||
TableGroupProducer tableGroupProducer,
|
||||
String sourceAlias,
|
||||
SqlAliasBase sqlAliasBase,
|
||||
|
@ -159,7 +159,28 @@ public class LazyTableGroup extends AbstractColumnReferenceQualifier implements
|
|||
public TableReference getTableReferenceInternal(
|
||||
NavigablePath navigablePath,
|
||||
String tableExpression) {
|
||||
if ( navigablePath == null || navigablePathChecker.test( navigablePath ) ) {
|
||||
/*
|
||||
todo (6.0): I think this could still return the wrong table reference in the following scenario
|
||||
a self-referential many-to-one association with a non-PK FK is join fetched
|
||||
The fetch for the property which is the FK target would be read from the parent which is wrong
|
||||
|
||||
@Entity
|
||||
class Book {
|
||||
@Id int id;
|
||||
String isbn;
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "parentIsbn", referenceColumnName = "isbn")
|
||||
Book parentBook;
|
||||
}
|
||||
|
||||
For data [Book(isbn=123),Book(isbn=456, parentBook=123)] the query
|
||||
`from Book b join fetch b.parentBook where b.isbn = '456'`
|
||||
would lead to to fetching [Book(isbn=123),Book(isbn=123, parentBook=123)].
|
||||
I think the solution for this would be to pass a boolean flag to skip the parent table group,
|
||||
which is always set when resolving for a fetch since the fetch needs the target property value
|
||||
*/
|
||||
|
||||
if ( navigablePath == null || navigablePathChecker.test( navigablePath, tableExpression ) ) {
|
||||
final TableReference reference = parentTableGroup.getTableReference(
|
||||
navigablePath,
|
||||
tableExpression
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.manytoone;
|
||||
package org.hibernate.orm.test.annotations.manytoone;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.manytoone;
|
||||
package org.hibernate.orm.test.annotations.manytoone;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import javax.persistence.Column;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.manytoone;
|
||||
package org.hibernate.orm.test.annotations.manytoone;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.manytoone;
|
||||
package org.hibernate.orm.test.annotations.manytoone;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.manytoone;
|
||||
package org.hibernate.orm.test.annotations.manytoone;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.manytoone;
|
||||
package org.hibernate.orm.test.annotations.manytoone;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
|
@ -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.annotations.manytoone;
|
||||
package org.hibernate.orm.test.annotations.manytoone;
|
||||
import java.util.Date;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.manytoone;
|
||||
package org.hibernate.orm.test.annotations.manytoone;
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.manytoone;
|
||||
package org.hibernate.orm.test.annotations.manytoone;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.manytoone;
|
||||
package org.hibernate.orm.test.annotations.manytoone;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import javax.persistence.CascadeType;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.manytoone;
|
||||
package org.hibernate.orm.test.annotations.manytoone;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embeddable;
|
|
@ -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.annotations.manytoone;
|
||||
package org.hibernate.orm.test.annotations.manytoone;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
@ -311,9 +311,9 @@ public class ManyToOneTest extends BaseCoreFunctionalTestCase {
|
|||
//2 many to one non pk pointing to the same referencedColumnName should not fail
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
org.hibernate.test.annotations.manytoone.Customer customer = new org.hibernate.test.annotations.manytoone.Customer();
|
||||
org.hibernate.orm.test.annotations.manytoone.Customer customer = new org.hibernate.orm.test.annotations.manytoone.Customer();
|
||||
customer.userId="123";
|
||||
org.hibernate.test.annotations.manytoone.Customer customer2 = new org.hibernate.test.annotations.manytoone.Customer();
|
||||
org.hibernate.orm.test.annotations.manytoone.Customer customer2 = new org.hibernate.orm.test.annotations.manytoone.Customer();
|
||||
customer2.userId="124";
|
||||
s.persist( customer2 );
|
||||
s.persist( customer );
|
||||
|
@ -365,7 +365,7 @@ public class ManyToOneTest extends BaseCoreFunctionalTestCase {
|
|||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[]{
|
||||
Deal.class,
|
||||
org.hibernate.test.annotations.manytoone.Customer.class,
|
||||
org.hibernate.orm.test.annotations.manytoone.Customer.class,
|
||||
Car.class,
|
||||
Color.class,
|
||||
Flight.class,
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.manytoone;
|
||||
package org.hibernate.orm.test.annotations.manytoone;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.manytoone;
|
||||
package org.hibernate.orm.test.annotations.manytoone;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embeddable;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.manytoone;
|
||||
package org.hibernate.orm.test.annotations.manytoone;
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
import javax.persistence.Column;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.manytoone;
|
||||
package org.hibernate.orm.test.annotations.manytoone;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.manytoone;
|
||||
package org.hibernate.orm.test.annotations.manytoone;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id$
|
||||
package org.hibernate.test.annotations.manytoone;
|
||||
package org.hibernate.orm.test.annotations.manytoone;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embeddable;
|
|
@ -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.annotations.manytoone;
|
||||
package org.hibernate.orm.test.annotations.manytoone;
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
import javax.persistence.CascadeType;
|
|
@ -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.annotations.manytoone;
|
||||
package org.hibernate.orm.test.annotations.manytoone;
|
||||
import java.io.Serializable;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$
|
||||
package org.hibernate.test.annotations.manytoone.referencedcolumnname;
|
||||
package org.hibernate.orm.test.annotations.manytoone.referencedcolumnname;
|
||||
import java.io.Serializable;
|
||||
import java.rmi.server.UID;
|
||||
import javax.persistence.GeneratedValue;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$
|
||||
package org.hibernate.test.annotations.manytoone.referencedcolumnname;
|
||||
package org.hibernate.orm.test.annotations.manytoone.referencedcolumnname;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
|
|
@ -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.annotations.manytoone.referencedcolumnname;
|
||||
package org.hibernate.orm.test.annotations.manytoone.referencedcolumnname;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$
|
||||
package org.hibernate.test.annotations.manytoone.referencedcolumnname;
|
||||
package org.hibernate.orm.test.annotations.manytoone.referencedcolumnname;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
@Entity
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$
|
||||
package org.hibernate.test.annotations.manytoone.referencedcolumnname;
|
||||
package org.hibernate.orm.test.annotations.manytoone.referencedcolumnname;
|
||||
import java.math.BigDecimal;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$
|
||||
package org.hibernate.test.annotations.manytoone.referencedcolumnname;
|
||||
package org.hibernate.orm.test.annotations.manytoone.referencedcolumnname;
|
||||
import java.math.BigDecimal;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
Loading…
Reference in New Issue