Skip to content

Commit

Permalink
HHH-17504 - Ongoing JPA 32 work
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sebersole committed Dec 5, 2023
1 parent 307aa43 commit f246394
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ protected static void applyCommonInformation(EntityTypeMetadata typeMetadata, Pe
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public SubclassEntityBinding(
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,
Expand All @@ -61,7 +61,7 @@ public SubclassEntityBinding(
bindingContext
);
final var table = primaryTable.table();
( (TableOwner) subclass ).setTable( table );
tableOwner.setTable( table );
}

applyDiscriminatorValue( typeMetadata, subclass );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,7 +29,7 @@
/**
* @author Steve Ebersole
*/
public class SimpleJoinedTests {
public class JoinedTests {
/**
* Allowing for something like:
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,11 +31,11 @@

/**
* @author Steve Ebersole
*/
public class SimpleSingleTableTests {
*/ @SuppressWarnings("JUnitMalformedDeclaration")

public class SingleTableTests {
@Test
@ServiceRegistry
@SuppressWarnings("JUnitMalformedDeclaration")
void testNoInheritance(ServiceRegistryScope scope) {
checkDomainModel(
(context) -> {
Expand All @@ -48,7 +51,6 @@ void testNoInheritance(ServiceRegistryScope scope) {

@Test
@ServiceRegistry
@SuppressWarnings("JUnitMalformedDeclaration")
void testImplicitDiscriminator(ServiceRegistryScope scope) {
checkDomainModel(
(context) -> {
Expand Down Expand Up @@ -78,7 +80,6 @@ void testImplicitDiscriminator(ServiceRegistryScope scope) {

@Test
@ServiceRegistry
@SuppressWarnings("JUnitMalformedDeclaration")
void testExplicitDiscriminator(ServiceRegistryScope scope) {
checkDomainModel(
(context) -> {
Expand Down Expand Up @@ -106,6 +107,31 @@ void testExplicitDiscriminator(ServiceRegistryScope scope) {
);
}

@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 {
Expand Down Expand Up @@ -144,21 +170,4 @@ public static class ExplicitRoot {
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,6 +14,11 @@
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;

Expand Down Expand Up @@ -55,4 +60,23 @@ void testSimpleModel(ServiceRegistryScope scope) {
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;
}
}

This file was deleted.

This file was deleted.

0 comments on commit f246394

Please sign in to comment.