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

View File

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

View File

@ -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.test.annotations.derivedidentities.e1.a;
package org.hibernate.orm.test.annotations.derivedidentities.e1.a;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;

View File

@ -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.test.annotations.derivedidentities.e1.a;
package org.hibernate.orm.test.annotations.derivedidentities.e1.a;
import java.io.Serializable;
/**

View File

@ -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.test.annotations.derivedidentities.e1.a;
package org.hibernate.orm.test.annotations.derivedidentities.e1.a;
import java.util.List;

View File

@ -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.test.annotations.derivedidentities.e1.a;
package org.hibernate.orm.test.annotations.derivedidentities.e1.a;
import jakarta.persistence.Entity;
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">
<composite-id class="CustomerId" mapped="true">

View File

@ -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.test.idclass;
package org.hibernate.orm.test.idclass;
public class Customer {
private String orgName;

View File

@ -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.test.idclass;
package org.hibernate.orm.test.idclass;
import java.io.Serializable;

View File

@ -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.test.idclass;
package org.hibernate.orm.test.idclass;
/**
* @author Emmanuel Bernard

View File

@ -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.test.idclass;
package org.hibernate.orm.test.idclass;
import org.junit.Test;
@ -20,9 +20,9 @@ import static org.junit.Assert.assertEquals;
/**
* @author Gavin King
*/
public class IdClassTest extends BaseCoreFunctionalTestCase {
public class IdClassHbmTest extends BaseCoreFunctionalTestCase {
public String[] getMappings() {
return new String[] { "idclass/Customer.hbm.xml" };
return new String[] { "/org/hibernate/orm/test/idclass/Customer.hbm.xml" };
}
@Override