Skip to content

HHH-19324 - Switch tests using hbm.xml to use mapping.xml #9956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@DomainModel(
annotatedClasses = { Person.class },
xmlMappings = "org/hibernate/community/dialect/Person.hbm.xml"
)
@DomainModel(annotatedClasses = Person.class)
@RequiresDialect(AltibaseDialect.class)
@SessionFactory
public class AltibaseFunctionsTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@
*/
package org.hibernate.community.dialect;

import java.sql.*;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.SequenceGenerator;

import java.sql.Date;
import java.sql.Blob;
import java.sql.Clob;

@Entity
public class Person {
@Id
@GeneratedValue
@SequenceGenerator(sequenceName = "PERSON_SEQ")
private int id;
private String name;
private Date birthDate;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
* @author Steve Ebersole
*/
public interface JaxbBasicMapping {
/**
* The attribute's name
*/
String getName();
void setName(String name);

JaxbUserTypeImpl getType();

void setType(JaxbUserTypeImpl value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
*/
package org.hibernate.boot.jaxb.mapping.spi;

import org.checkerframework.checker.nullness.qual.Nullable;

/**
* @author Steve Ebersole
*/
public interface JaxbEmbeddable extends JaxbManagedType {
@Nullable
String getName();
void setName(@Nullable String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,13 @@ public Column[] getOverriddenColumn(String propertyName) {

private String extractUserPropertyName(String redundantString, String propertyName) {
String className = component.getOwner().getClassName();
boolean specialCase = propertyName.startsWith(className)
&& propertyName.length() > className.length() + 2 + redundantString.length() // .id.
&& propertyName.substring( className.length() + 1, className.length() + 1 + redundantString.length() )
.equals(redundantString);
if (specialCase) {
//remove id we might be in a @IdClass case
return className + propertyName.substring( className.length() + 1 + redundantString.length() );
if ( className != null && propertyName.startsWith( className ) ) {
boolean specialCase = propertyName.length() > className.length() + 2 + redundantString.length()
&& propertyName.substring( className.length() + 1, className.length() + 1 + redundantString.length() ).equals( redundantString );
if ( specialCase ) {
//remove id we might be in a @IdClass case
return className + propertyName.substring( className.length() + 1 + redundantString.length() );
}
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.hibernate.boot.model.IdentifierGeneratorDefinition;
import org.hibernate.boot.models.HibernateAnnotations;
import org.hibernate.boot.models.JpaAnnotations;
import org.hibernate.boot.models.annotations.internal.GenericGeneratorAnnotation;
import org.hibernate.boot.models.spi.GenericGeneratorRegistration;
import org.hibernate.boot.models.spi.GlobalRegistrations;
import org.hibernate.boot.models.spi.SequenceGeneratorRegistration;
Expand Down Expand Up @@ -351,6 +352,21 @@ protected void handleNamedAutoGenerator() {
}

private boolean handleAsLocalAutoGenerator() {
if ( "increment".equals( generatedValue.generator() ) ) {
final GenericGeneratorAnnotation incrementGenerator = new GenericGeneratorAnnotation( buildingContext.getBootstrapContext().getModelsContext() );
incrementGenerator.name( "increment" );
incrementGenerator.strategy( "increment" );

GeneratorAnnotationHelper.handleGenericGenerator(
generatedValue.generator(),
incrementGenerator,
entityMapping,
idValue,
buildingContext
);
return true;
}

final String generator = generatedValue.generator();
assert !generator.isEmpty();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.config.spi.StandardConverters;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.mapping.Table;
import org.hibernate.models.internal.MutableClassDetailsRegistry;
Expand Down Expand Up @@ -431,24 +432,28 @@ public static DomainModelSource processManagedResources(
);

final HashSet<String> categorizedClassNames = new HashSet<>();
allKnownClassNames.forEach( (className) -> applyKnownClass(
className,
categorizedClassNames,
classDetailsRegistry,
modelCategorizationCollector
) );
xmlPreProcessingResult.getMappedNames().forEach( (className) -> applyKnownClass(
className,
categorizedClassNames,
classDetailsRegistry,
modelCategorizationCollector
) );
// apply known classes
allKnownClassNames.forEach( (className) -> {
if ( categorizedClassNames.add( className ) ) {
// not known yet
final ClassDetails classDetails = classDetailsRegistry.resolveClassDetails( className );
applyKnownClass( classDetails, categorizedClassNames, classDetailsRegistry, modelCategorizationCollector );
}
} );
// apply known "names" - generally this handles dynamic models
xmlPreProcessingResult.getMappedNames().forEach( (mappedName) -> {
if ( categorizedClassNames.add( mappedName ) ) {
// not known yet
final ClassDetails classDetails = classDetailsRegistry.resolveClassDetails( mappedName );
applyKnownClass( classDetails, categorizedClassNames, classDetailsRegistry, modelCategorizationCollector );
}
} );

xmlProcessingResult.apply();

return new DomainModelSource(
classDetailsRegistry,
allKnownClassNames,
CollectionHelper.mutableJoin( allKnownClassNames, xmlPreProcessingResult.getMappedNames() ),
modelCategorizationCollector.getGlobalRegistrations(),
rootMappingDefaults,
aggregatedPersistenceUnitMetadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
*/
package org.hibernate.boot.models.internal;

import java.sql.Blob;
import java.sql.Clob;
import java.sql.NClob;
import java.util.function.Supplier;

import org.hibernate.annotations.TenantId;
import org.hibernate.models.internal.MutableClassDetailsRegistry;
import org.hibernate.models.internal.jdk.JdkClassDetails;
import org.hibernate.models.spi.ClassDetails;
import org.hibernate.models.spi.ClassDetailsRegistry;
import org.hibernate.models.spi.RegistryPrimer;
Expand All @@ -21,6 +25,18 @@ public class ModelsHelper {
public static void preFillRegistries(RegistryPrimer.Contributions contributions, ModelsContext buildingContext) {
OrmAnnotationHelper.forEachOrmAnnotation( contributions::registerAnnotation );

registerPrimitive( boolean.class, buildingContext );
registerPrimitive( byte.class, buildingContext );
registerPrimitive( short.class, buildingContext );
registerPrimitive( int.class, buildingContext );
registerPrimitive( long.class, buildingContext );
registerPrimitive( double.class, buildingContext );
registerPrimitive( float.class, buildingContext );
registerPrimitive( char.class, buildingContext );
registerPrimitive( Blob.class, buildingContext );
registerPrimitive( Clob.class, buildingContext );
registerPrimitive( NClob.class, buildingContext );

buildingContext.getAnnotationDescriptorRegistry().getDescriptor( TenantId.class );

// if ( buildingContext instanceof JandexModelBuildingContext ) {
Expand Down Expand Up @@ -57,6 +73,12 @@ public static void preFillRegistries(RegistryPrimer.Contributions contributions,
// }
}

private static void registerPrimitive(Class<?> theClass, ModelsContext buildingContext) {
final MutableClassDetailsRegistry classDetailsRegistry = buildingContext.getClassDetailsRegistry().as( MutableClassDetailsRegistry.class );
classDetailsRegistry.addClassDetails( new JdkClassDetails( theClass, buildingContext ) );

}

public static ClassDetails resolveClassDetails(
String className,
ClassDetailsRegistry classDetailsRegistry,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.boot.models.xml;

import org.hibernate.HibernateException;

/**
* Indicates a problem resolving an attribute's type details - typically with dynamic models.
*
* @author Steve Ebersole
*/
public class UnknownAttributeTypeException extends HibernateException {
public UnknownAttributeTypeException(String message) {
super( message );
}
}
Loading