HHH-17504 - Ongoing JPA 32 work
HHH-17350 - Work on hibernate-models, XSD and JAXB HHH-16114 - Improve boot metamodel binding HHH-15996 - Develop an abstraction for Annotation in annotation processing HHH-16012 - Develop an abstraction for domain model Class refs HHH-15997 - Support for dynamic models in orm.xml HHH-15698 - Support for entity-name in mapping.xsd
This commit is contained in:
parent
2eb3da331b
commit
753fafe9f4
|
@ -120,6 +120,10 @@ public abstract class EntityBinding extends IdentifiableTypeBinding {
|
|||
applySynchronizedTableNames( typeMetadata, persistentClass, bindingState );
|
||||
}
|
||||
|
||||
/**
|
||||
* @apiNote Not part of {@linkplain #applyCommonInformation} to allow the difference that we
|
||||
* do not always want this for the root entity
|
||||
*/
|
||||
protected static void applyDiscriminatorValue(
|
||||
EntityTypeMetadata typeMetadata,
|
||||
PersistentClass persistentClass) {
|
||||
|
|
|
@ -52,7 +52,7 @@ public class SubclassEntityBinding extends EntityBinding {
|
|||
applyNaming( typeMetadata, subclass, bindingState );
|
||||
bindingState.registerTypeBinding( getTypeMetadata(), this );
|
||||
|
||||
if ( subclass instanceof TableOwner ) {
|
||||
if ( subclass instanceof TableOwner tableOwner ) {
|
||||
final var primaryTable = TableHelper.bindPrimaryTable(
|
||||
typeMetadata,
|
||||
EntityHierarchy.HierarchyRelation.SUB,
|
||||
|
@ -61,7 +61,7 @@ public class SubclassEntityBinding extends EntityBinding {
|
|||
bindingContext
|
||||
);
|
||||
final var table = primaryTable.table();
|
||||
( (TableOwner) subclass ).setTable( table );
|
||||
tableOwner.setTable( table );
|
||||
}
|
||||
|
||||
applyDiscriminatorValue( typeMetadata, subclass );
|
||||
|
|
|
@ -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.orm.test.boot.models.bind.joined;
|
||||
package org.hibernate.orm.test.boot.models.bind.inheritance;
|
||||
|
||||
import org.hibernate.mapping.JoinedSubclass;
|
||||
import org.hibernate.mapping.RootClass;
|
||||
|
@ -29,7 +29,7 @@ import static org.hibernate.orm.test.boot.models.bind.BindingTestingHelper.check
|
|||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SimpleJoinedTests {
|
||||
public class JoinedTests {
|
||||
/**
|
||||
* Allowing for something like:
|
||||
*
|
|
@ -4,11 +4,14 @@
|
|||
* 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.orm.test.boot.models.bind.discriminated;
|
||||
package org.hibernate.orm.test.boot.models.bind.inheritance;
|
||||
|
||||
import org.hibernate.mapping.BasicValue;
|
||||
import org.hibernate.mapping.Column;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.mapping.RootClass;
|
||||
import org.hibernate.mapping.SingleTableSubclass;
|
||||
import org.hibernate.mapping.Subclass;
|
||||
|
||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||
import org.hibernate.testing.orm.junit.ServiceRegistryScope;
|
||||
|
@ -28,11 +31,11 @@ import static org.hibernate.orm.test.boot.models.bind.BindingTestingHelper.check
|
|||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SimpleSingleTableTests {
|
||||
*/ @SuppressWarnings("JUnitMalformedDeclaration")
|
||||
|
||||
public class SingleTableTests {
|
||||
@Test
|
||||
@ServiceRegistry
|
||||
@SuppressWarnings("JUnitMalformedDeclaration")
|
||||
void testNoInheritance(ServiceRegistryScope scope) {
|
||||
checkDomainModel(
|
||||
(context) -> {
|
||||
|
@ -48,7 +51,6 @@ public class SimpleSingleTableTests {
|
|||
|
||||
@Test
|
||||
@ServiceRegistry
|
||||
@SuppressWarnings("JUnitMalformedDeclaration")
|
||||
void testImplicitDiscriminator(ServiceRegistryScope scope) {
|
||||
checkDomainModel(
|
||||
(context) -> {
|
||||
|
@ -78,7 +80,6 @@ public class SimpleSingleTableTests {
|
|||
|
||||
@Test
|
||||
@ServiceRegistry
|
||||
@SuppressWarnings("JUnitMalformedDeclaration")
|
||||
void testExplicitDiscriminator(ServiceRegistryScope scope) {
|
||||
checkDomainModel(
|
||||
(context) -> {
|
||||
|
@ -106,6 +107,31 @@ public class SimpleSingleTableTests {
|
|||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ServiceRegistry
|
||||
void testAttributes(ServiceRegistryScope scope) {
|
||||
checkDomainModel(
|
||||
(context) -> {
|
||||
final var metadataCollector = context.getMetadataCollector();
|
||||
final RootClass rootBinding = (RootClass) metadataCollector.getEntityBinding( Root.class.getName() );
|
||||
final SingleTableSubclass subBinding = (SingleTableSubclass) metadataCollector.getEntityBinding( Sub.class.getName() );
|
||||
|
||||
assertThat( rootBinding.getDeclaredProperties() ).hasSize( 2 );
|
||||
assertThat( rootBinding.getProperties() ).hasSize( 2 );
|
||||
assertThat( rootBinding.getPropertyClosure() ).hasSize( 2 );
|
||||
assertThat( rootBinding.getSubclassPropertyClosure() ).hasSize( 3 );
|
||||
|
||||
assertThat( subBinding.getDeclaredProperties() ).hasSize( 1 );
|
||||
assertThat( subBinding.getProperties() ).hasSize( 1 );
|
||||
assertThat( subBinding.getPropertyClosure() ).hasSize( 3 );
|
||||
assertThat( subBinding.getSubclassPropertyClosure() ).hasSize( 3 );
|
||||
},
|
||||
scope.getRegistry(),
|
||||
Root.class,
|
||||
Sub.class
|
||||
);
|
||||
}
|
||||
|
||||
@Entity(name="Single")
|
||||
@Table(name="Single")
|
||||
public static class Single {
|
||||
|
@ -144,21 +170,4 @@ public class SimpleSingleTableTests {
|
|||
public static class ExplicitSub extends ExplicitRoot {
|
||||
private String details;
|
||||
}
|
||||
|
||||
@Entity(name="ExplicitRoot")
|
||||
@Table(name="data2")
|
||||
@Inheritance(strategy = InheritanceType.JOINED)
|
||||
@DiscriminatorColumn(name = "type_discriminator", discriminatorType = DiscriminatorType.CHAR, length = 1)
|
||||
@DiscriminatorValue( "R" )
|
||||
public static class JoinedRoot {
|
||||
@Id
|
||||
private Integer id;
|
||||
private String name;
|
||||
}
|
||||
|
||||
@Entity(name="Sub")
|
||||
@DiscriminatorValue( "S" )
|
||||
public static class JoinedSub extends JoinedRoot {
|
||||
private String details;
|
||||
}
|
||||
}
|
|
@ -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.orm.test.boot.models.bind.union;
|
||||
package org.hibernate.orm.test.boot.models.bind.inheritance;
|
||||
|
||||
import org.hibernate.mapping.DenormalizedTable;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
|
@ -14,6 +14,11 @@ import org.hibernate.testing.orm.junit.ServiceRegistry;
|
|||
import org.hibernate.testing.orm.junit.ServiceRegistryScope;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Inheritance;
|
||||
import jakarta.persistence.InheritanceType;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hibernate.orm.test.boot.models.bind.BindingTestingHelper.checkDomainModel;
|
||||
|
||||
|
@ -55,4 +60,23 @@ public class UnionSubclassTests {
|
|||
UnionSub.class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@Entity
|
||||
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
|
||||
public static class UnionRoot {
|
||||
@Id
|
||||
private Integer id;
|
||||
private String name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@Entity
|
||||
public static class UnionSub extends UnionRoot {
|
||||
private String unionData;
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* 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.orm.test.boot.models.bind.union;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Inheritance;
|
||||
import jakarta.persistence.InheritanceType;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@Entity
|
||||
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
|
||||
public class UnionRoot {
|
||||
@Id
|
||||
private Integer id;
|
||||
private String name;
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* 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.orm.test.boot.models.bind.union;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@Entity
|
||||
public class UnionSub extends UnionRoot {
|
||||
private String unionData;
|
||||
}
|
Loading…
Reference in New Issue