Fix HBM based model binding wrt id-classes and move the last derived id tests

This commit is contained in:
Christian Beikov 2021-11-16 18:05:41 +01:00
parent b8429bca42
commit eaea919cf5
11 changed files with 25 additions and 19 deletions

View File

@ -857,6 +857,7 @@ public class ModelBinder {
idClassName, idClassName,
rootEntityDescriptor.getClassName(), rootEntityDescriptor.getClassName(),
idPropertyName, idPropertyName,
idPropertyName == null,
idClassName == null && idPropertyName == null, idClassName == null && idPropertyName == null,
identifierSource.getEmbeddableSource().isDynamic(), identifierSource.getEmbeddableSource().isDynamic(),
identifierSource.getIdentifierAttributeSource().getXmlNodeName() identifierSource.getIdentifierAttributeSource().getXmlNodeName()
@ -902,6 +903,7 @@ public class ModelBinder {
idClassName, idClassName,
rootEntityDescriptor.getClassName(), rootEntityDescriptor.getClassName(),
null, null,
true,
idClassName == null, idClassName == null,
false, false,
null null
@ -921,11 +923,13 @@ public class ModelBinder {
null, null,
null, null,
true, true,
true,
false, false,
null null
); );
rootEntityDescriptor.setIdentifierMapper(mapper); rootEntityDescriptor.setIdentifierMapper( mapper );
rootEntityDescriptor.setDeclaredIdentifierMapper( mapper );
Property property = new Property(); Property property = new Property();
property.setName( PropertyPath.IDENTIFIER_MAPPER_PROPERTY ); property.setName( PropertyPath.IDENTIFIER_MAPPER_PROPERTY );
property.setUpdateable( false ); property.setUpdateable( false );
@ -2658,6 +2662,7 @@ public class ModelBinder {
explicitComponentClassName, explicitComponentClassName,
containingClassName, containingClassName,
propertyName, propertyName,
false,
isVirtual, isVirtual,
embeddableSource.isDynamic(), embeddableSource.isDynamic(),
xmlNodeName xmlNodeName
@ -2680,6 +2685,7 @@ public class ModelBinder {
String explicitComponentClassName, String explicitComponentClassName,
String containingClassName, String containingClassName,
String propertyName, String propertyName,
boolean isComponentEmbedded,
boolean isVirtual, boolean isVirtual,
boolean isDynamic, boolean isDynamic,
String xmlNodeName) { String xmlNodeName) {
@ -2688,7 +2694,7 @@ public class ModelBinder {
componentBinding.setRoleName( role ); componentBinding.setRoleName( role );
componentBinding.setEmbedded( isVirtual ); componentBinding.setEmbedded( isComponentEmbedded );
// todo : better define the conditions in this if/else // todo : better define the conditions in this if/else
if ( isDynamic ) { if ( isDynamic ) {

View File

@ -407,11 +407,9 @@ public class MetadataContext {
final EmbeddableTypeImpl<?> idClassType; final EmbeddableTypeImpl<?> idClassType;
final Component identifierMapper = persistentClass.getIdentifierMapper(); final Component identifierMapper = persistentClass.getIdentifierMapper();
if ( identifierMapper != null ) { if ( identifierMapper != null ) {
// cidPropertyItr = cidValue.getPropertyIterator();
// propertySpan = cidValue.getPropertySpan();
cidPropertyItr = identifierMapper.getPropertyIterator(); cidPropertyItr = identifierMapper.getPropertyIterator();
propertySpan = identifierMapper.getPropertySpan(); propertySpan = identifierMapper.getPropertySpan();
idClassType = applyIdClassMetadata( (Component) persistentClass.getIdentifier(), identifierMapper ); idClassType = applyIdClassMetadata( (Component) persistentClass.getIdentifier() );
} }
else { else {
cidPropertyItr = cidValue.getPropertyIterator(); cidPropertyItr = cidValue.getPropertyIterator();
@ -441,17 +439,19 @@ public class MetadataContext {
} }
} }
private EmbeddableTypeImpl<?> applyIdClassMetadata(Component identifier, Component idClass) { private EmbeddableTypeImpl<?> applyIdClassMetadata(Component idClassComponent) {
final JavaTypeRegistry registry = getTypeConfiguration() final JavaTypeRegistry registry = getTypeConfiguration()
.getJavaTypeDescriptorRegistry(); .getJavaTypeDescriptorRegistry();
final Class<?> componentClass = identifier.getComponentClass(); final Class<?> componentClass = idClassComponent.getComponentClass();
final JavaType<?> javaTypeDescriptor = registry.resolveManagedTypeDescriptor( componentClass ); final JavaType<?> javaTypeDescriptor = registry.resolveManagedTypeDescriptor( componentClass );
return new EmbeddableTypeImpl<>( final EmbeddableTypeImpl<?> embeddableType = new EmbeddableTypeImpl<>(
javaTypeDescriptor, javaTypeDescriptor,
false, false,
getJpaMetamodel() getJpaMetamodel()
); );
registerEmbeddableType( embeddableType, idClassComponent );
return embeddableType;
} }
@SuppressWarnings({"unchecked", "rawtypes"}) @SuppressWarnings({"unchecked", "rawtypes"})

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.annotations.derivedidentities.e1.a; package org.hibernate.orm.test.annotations.derivedidentities.e1.a;
import jakarta.persistence.CascadeType; import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.annotations.derivedidentities.e1.a; package org.hibernate.orm.test.annotations.derivedidentities.e1.a;
import java.io.Serializable; import java.io.Serializable;
/** /**

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.annotations.derivedidentities.e1.a; package org.hibernate.orm.test.annotations.derivedidentities.e1.a;
import java.util.List; import java.util.List;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.annotations.derivedidentities.e1.a; package org.hibernate.orm.test.annotations.derivedidentities.e1.a;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;

View File

@ -18,7 +18,7 @@
--> -->
<hibernate-mapping package="org.hibernate.test.idclass"> <hibernate-mapping package="org.hibernate.orm.test.idclass">
<class name="Customer"> <class name="Customer">
<composite-id class="CustomerId" mapped="true"> <composite-id class="CustomerId" mapped="true">

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.idclass; package org.hibernate.orm.test.idclass;
public class Customer { public class Customer {
private String orgName; private String orgName;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.idclass; package org.hibernate.orm.test.idclass;
import java.io.Serializable; import java.io.Serializable;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.idclass; package org.hibernate.orm.test.idclass;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.idclass; package org.hibernate.orm.test.idclass;
import org.junit.Test; import org.junit.Test;
@ -20,9 +20,9 @@ import static org.junit.Assert.assertEquals;
/** /**
* @author Gavin King * @author Gavin King
*/ */
public class IdClassTest extends BaseCoreFunctionalTestCase { public class IdClassHbmTest extends BaseCoreFunctionalTestCase {
public String[] getMappings() { public String[] getMappings() {
return new String[] { "idclass/Customer.hbm.xml" }; return new String[] { "/org/hibernate/orm/test/idclass/Customer.hbm.xml" };
} }
@Override @Override