HHH-12332 - Test and fix for unrelated same named collection attributes in subtypes
This commit is contained in:
parent
2bd1db2d4e
commit
f2d77a033e
|
@ -193,8 +193,17 @@ public abstract class AbstractPropertyMapping implements PropertyMapping {
|
|||
return;
|
||||
}
|
||||
|
||||
throw new IllegalStateException( "Collection mapping in abstract entity type with a type variable is unsupported! Couldn't add property '"
|
||||
+ path + "' with type: " + type );
|
||||
// When we discover incompatible types, we register "null" as property type to signal that the property is not resolvable on the parent type
|
||||
newType = null;
|
||||
if ( LOG.isTraceEnabled() ) {
|
||||
LOG.tracev(
|
||||
"Skipped adding same named type incompatible property to base type [{0}] for property [{1}], existing type = [{2}], incoming type = [{3}]",
|
||||
getEntityName(),
|
||||
path,
|
||||
existingType,
|
||||
type
|
||||
);
|
||||
}
|
||||
}
|
||||
else if ( type instanceof EntityType ) {
|
||||
EntityType entityType1 = (EntityType) existingType;
|
||||
|
|
|
@ -26,8 +26,12 @@ package org.hibernate.test.inheritance.discriminator;
|
|||
import org.hibernate.Session;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Test cases for joined inheritance with a discriminator column.
|
||||
*
|
||||
|
@ -37,7 +41,15 @@ public class JoinedInheritanceTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] { Polygon.class, Quadrilateral.class };
|
||||
return new Class[] {
|
||||
Polygon.class,
|
||||
Quadrilateral.class,
|
||||
BaseEntity.class,
|
||||
EntityA.class,
|
||||
EntityB.class,
|
||||
EntityC.class,
|
||||
EntityD.class
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -63,4 +75,53 @@ public class JoinedInheritanceTest extends BaseCoreFunctionalTestCase {
|
|||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-12332" )
|
||||
public void joinUnrelatedCollectionOnBaseType() {
|
||||
final Session s = openSession();
|
||||
s.getTransaction().begin();
|
||||
|
||||
try {
|
||||
s.createQuery("from BaseEntity b join b.attributes").list();
|
||||
Assert.fail("Expected a resolution exception for property 'attributes'!");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
Assert.assertTrue(ex.getMessage().contains("could not resolve property: attributes "));
|
||||
} finally {
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
// Test entities for metamodel building for HHH-12332
|
||||
@Entity(name = "BaseEntity")
|
||||
@Inheritance(strategy = InheritanceType.JOINED)
|
||||
public static class BaseEntity {
|
||||
@Id
|
||||
private long id;
|
||||
}
|
||||
|
||||
@Entity(name = "EntityA")
|
||||
public static class EntityA extends BaseEntity {
|
||||
@OneToMany(fetch = FetchType.LAZY)
|
||||
private Set<EntityC> attributes;
|
||||
}
|
||||
|
||||
@Entity(name = "EntityB")
|
||||
public static class EntityB extends BaseEntity {
|
||||
@OneToMany(fetch = FetchType.LAZY)
|
||||
private Set<EntityD> attributes;
|
||||
}
|
||||
|
||||
@Entity(name = "EntityC")
|
||||
public static class EntityC {
|
||||
@Id
|
||||
private long id;
|
||||
}
|
||||
|
||||
@Entity(name = "EntityD")
|
||||
public static class EntityD {
|
||||
@Id
|
||||
private long id;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue