HHH-7615: Changed ToOneAttributeSourceImpl.getJoinColumns to call JoinColumnResolutionContext.resolveRelationalValuesForAttribute when attributeName is null (indicating to use the primary key of the referenced table), and likewise modified resolveRelationalValuesForAttribute methods in each JoineColumnResolutionContext impl within Binder extract the PK columns when the attribute name is null

This commit is contained in:
John Verhaeg 2012-09-18 04:37:49 -05:00
parent dcc4ab49e7
commit f48503891b
7 changed files with 19 additions and 10 deletions

View File

@ -1950,6 +1950,13 @@ public class Binder {
@Override
public List< Value > resolveRelationalValuesForAttribute( String attributeName ) {
if ( attributeName == null ) {
List< Value > values = new ArrayList< Value >();
for ( Column column : entityBinding.getPrimaryTable().getPrimaryKey().getColumns() ) {
values.add( column );
}
return values;
}
final AttributeBinding referencedAttributeBinding =
entityBinding.locateAttributeBinding( attributeName );
if ( referencedAttributeBinding == null ) {
@ -2311,6 +2318,13 @@ public class Binder {
@Override
public List< Value > resolveRelationalValuesForAttribute( String attributeName ) {
if ( attributeName == null ) {
List< Value > values = new ArrayList< Value >();
for ( Column column : referencedEntityBinding.getPrimaryTable().getPrimaryKey().getColumns() ) {
values.add( column );
}
return values;
}
final AttributeBinding referencedAttributeBinding =
referencedEntityBinding.locateAttributeBinding( attributeName );
if ( !referencedAttributeBinding.getAttribute().isSingular() ) {

View File

@ -149,6 +149,9 @@ public class ToOneAttributeSourceImpl extends SingularAttributeSourceImpl implem
public List<Value> getJoinColumns(JoinColumnResolutionContext context) {
final List<Value> values = new ArrayList<Value>();
for ( Column column : associationAttribute.getJoinColumnValues() ) {
if ( column.getReferencedColumnName() == null ) {
return context.resolveRelationalValuesForAttribute( null );
}
org.hibernate.metamodel.spi.relational.Column resolvedColumn = context.resolveColumn(
column.getReferencedColumnName(),
logicalJoinTableName,

View File

@ -31,7 +31,6 @@ import org.hibernate.metamodel.spi.binding.HibernateTypeDescriptor;
import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
import org.hibernate.test.annotations.loader.Player;
import org.hibernate.test.annotations.loader.Team;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.hibernate.testing.junit4.BaseAnnotationBindingTestCase;
import org.hibernate.testing.junit4.Resources;
@ -44,7 +43,6 @@ import static org.junit.Assert.assertTrue;
public class OneToManyBindingTest extends BaseAnnotationBindingTestCase {
@Test
@Resources(annotatedClasses = { Team.class, Player.class })
@FailureExpectedWithNewMetamodel(jiraKey = "HHH-7549")
public void testPluralAttributeBindingTest() {
EntityBinding playerBinding = getEntityBinding( Player.class );
assertNotNull( playerBinding );

View File

@ -26,7 +26,6 @@ package org.hibernate.metamodel.spi.binding;
import org.junit.Test;
import org.hibernate.metamodel.MetadataSources;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
/**
* Basic tests of annotation based binding code
@ -56,8 +55,9 @@ public class BasicAnnotationBindingTests extends AbstractBasicBindingTests {
sources.addAnnotatedClass( SimpleEntityWithSimpleComponent.SimpleComponent.class );
}
@Override
@Test
@FailureExpectedWithNewMetamodel(jiraKey = "HHH-7549")
// @FailureExpectedWithNewMetamodel(jiraKey = "HHH-7549")
public void testEntityWithManyToOneMapping() {
super.testEntityWithManyToOneMapping();
}

View File

@ -31,7 +31,6 @@ import org.junit.Test;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import static org.junit.Assert.assertEquals;
@ -94,7 +93,6 @@ import static org.junit.Assert.assertEquals;
* @author Chris Wilson
* @link https://hibernate.onjira.com/browse/HHH-4630
*/
@FailureExpectedWithNewMetamodel
public class ComplexJoinAliasTest extends BaseCoreFunctionalTestCase {
@Override

View File

@ -28,13 +28,11 @@ import org.hibernate.criterion.Restrictions;
import org.junit.Test;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
/**
* @author Steve Ebersole
*/
@FailureExpectedWithNewMetamodel // NPE @ Binder.bindManyToOneAttribute(Binder.java:1053)
public class JoinSelfReferentialFetchProfileTest extends BaseCoreFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {

View File

@ -32,7 +32,6 @@ import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import static org.junit.Assert.assertEquals;
@ -40,7 +39,6 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@FailureExpectedWithNewMetamodel
public class LazyLoadingTest extends BaseCoreFunctionalTestCase {
@Before