diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/internal/factory/PersistentClassWrapperFactory.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/internal/factory/PersistentClassWrapperFactory.java index 7354170ad1..0f40c27460 100644 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/internal/factory/PersistentClassWrapperFactory.java +++ b/jbt/src/main/java/org/hibernate/tool/orm/jbt/internal/factory/PersistentClassWrapperFactory.java @@ -328,7 +328,7 @@ public boolean isDiscriminatorValueNull() { @Override public boolean isExplicitPolymorphism() { - return persistentClass.isExplicitPolymorphism(); + return false; } @Override diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/api/wrp/PersistentClassWrapperTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/api/wrp/PersistentClassWrapperTest.java index 43be969a09..fbfa00478f 100644 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/api/wrp/PersistentClassWrapperTest.java +++ b/jbt/src/test/java/org/hibernate/tool/orm/jbt/api/wrp/PersistentClassWrapperTest.java @@ -935,13 +935,7 @@ public void testIsExplicitPolymorphism() { assertFalse(rootClassWrapper.isExplicitPolymorphism()); assertFalse(singleTableSubclassWrapper.isExplicitPolymorphism()); assertFalse(joinedSubclassWrapper.isExplicitPolymorphism()); - ((RootClass)rootClassTarget).setExplicitPolymorphism(true); - assertTrue(rootClassWrapper.isExplicitPolymorphism()); - assertTrue(singleTableSubclassWrapper.isExplicitPolymorphism()); - assertTrue(joinedSubclassWrapper.isExplicitPolymorphism()); assertFalse(specialRootClassWrapper.isExplicitPolymorphism()); - ((RootClass)specialRootClassTarget).setExplicitPolymorphism(true); - assertTrue(specialRootClassWrapper.isExplicitPolymorphism()); } @Test diff --git a/maven/src/main/java/org/hibernate/tool/maven/TransformHbmMojo.java b/maven/src/main/java/org/hibernate/tool/maven/TransformHbmMojo.java index 7cf1928e1a..4ae75e5113 100644 --- a/maven/src/main/java/org/hibernate/tool/maven/TransformHbmMojo.java +++ b/maven/src/main/java/org/hibernate/tool/maven/TransformHbmMojo.java @@ -13,6 +13,7 @@ import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; +import org.hibernate.boot.MetadataSources; import org.hibernate.boot.jaxb.Origin; import org.hibernate.boot.jaxb.SourceType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmHibernateMapping; @@ -21,6 +22,11 @@ import org.hibernate.boot.jaxb.internal.MappingBinder; import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappingsImpl; import org.hibernate.boot.jaxb.spi.Binding; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.boot.spi.MetadataImplementor; +import org.hibernate.cfg.JdbcSettings; +import org.hibernate.dialect.H2Dialect; +import org.hibernate.service.ServiceRegistry; import jakarta.xml.bind.JAXBException; import jakarta.xml.bind.Marshaller; @@ -36,13 +42,41 @@ public void execute() throws MojoExecutionException, MojoFailureException { MappingBinder mappingBinder = new MappingBinder( MappingBinder.class.getClassLoader()::getResourceAsStream, UnsupportedFeatureHandling.ERROR); - Marshaller marshaller = createMarshaller(mappingBinder); List hbmFiles = getHbmFiles(inputFolder); List> hbmMappings = getHbmMappings(hbmFiles, mappingBinder); - List> transformed = - HbmXmlTransformer.transform(hbmMappings, UnsupportedFeatureHandling.ERROR); - for (int i = 0; i < hbmFiles.size(); i++) { - marshall(marshaller, transformed.get(i).getRoot(), hbmFiles.get(i)); + performTransformation(hbmMappings, mappingBinder, createServiceRegistry()); + } + + private ServiceRegistry createServiceRegistry() { + StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder(); + ssrb.clearSettings(); + ssrb.applySetting(JdbcSettings.ALLOW_METADATA_ON_BOOT, false); + // Choose the H2 dialect by default, make this configurable + ssrb.applySetting(JdbcSettings.DIALECT, H2Dialect.class.getName()); + return ssrb.build(); + } + + private void performTransformation( + List> hbmBindings, + MappingBinder mappingBinder, + ServiceRegistry serviceRegistry) { + Marshaller marshaller = createMarshaller(mappingBinder); + MetadataSources metadataSources = new MetadataSources( serviceRegistry ); + hbmBindings.forEach( metadataSources::addHbmXmlBinding ); + List> transformedBindings = HbmXmlTransformer.transform( + hbmBindings, + (MetadataImplementor) metadataSources.buildMetadata(), + serviceRegistry, + UnsupportedFeatureHandling.ERROR + ); + for (int i = 0; i < hbmBindings.size(); i++) { + Binding hbmBinding = hbmBindings.get( i ); + Binding transformedBinding = transformedBindings.get( i ); + + HbmXmlOrigin origin = (HbmXmlOrigin)hbmBinding.getOrigin(); + File hbmXmlFile = origin.getHbmXmlFile(); + + marshall(marshaller, transformedBinding.getRoot(), hbmXmlFile); } } @@ -51,7 +85,7 @@ private List> getHbmMappings(List hbmXmlF hbmXmlFiles.forEach((hbmXmlFile) -> { final String fullPath = hbmXmlFile.getAbsolutePath(); getLog().info("Adding file: '" + fullPath + "' to the list to be transformed."); - Origin origin = new Origin(SourceType.FILE, hbmXmlFile.getAbsolutePath()); + Origin origin = new HbmXmlOrigin(hbmXmlFile); Binding binding = bindMapping( mappingBinder, hbmXmlFile, origin ); result.add(binding); }); @@ -107,4 +141,21 @@ private List getHbmFiles(File f) { return result; } + private class HbmXmlOrigin extends Origin { + + private static final long serialVersionUID = 1L; + + private final File hbmXmlFile; + + public HbmXmlOrigin(File hbmXmlFile) { + super( SourceType.FILE, hbmXmlFile.getAbsolutePath() ); + this.hbmXmlFile = hbmXmlFile; + } + + public File getHbmXmlFile() { + return hbmXmlFile; + } + + } + } diff --git a/orm/src/main/java/org/hibernate/tool/internal/export/java/EntityPOJOClass.java b/orm/src/main/java/org/hibernate/tool/internal/export/java/EntityPOJOClass.java index 425cc26937..3d56d2b3c1 100644 --- a/orm/src/main/java/org/hibernate/tool/internal/export/java/EntityPOJOClass.java +++ b/orm/src/main/java/org/hibernate/tool/internal/export/java/EntityPOJOClass.java @@ -509,7 +509,7 @@ else if ( "delete-orphan".equals( element ) ) { } else if ( "save-update".equals( element ) ) { if (cascadeType == null) cascadeType = importType( "org.hibernate.annotations.CascadeType"); - cascade.append( cascadeType ).append(".SAVE_UPDATE").append(", "); + cascade.append( cascadeType ).append(".MERGE").append(", "); } else if ( "replicate".equals( element ) ) { if (cascadeType == null) cascadeType = importType( "org.hibernate.annotations.CascadeType"); diff --git a/orm/src/main/java/org/hibernate/tool/internal/reveng/binder/CollectionSecondPass.java b/orm/src/main/java/org/hibernate/tool/internal/reveng/binder/CollectionSecondPass.java index 760c1b306f..22afde26ff 100644 --- a/orm/src/main/java/org/hibernate/tool/internal/reveng/binder/CollectionSecondPass.java +++ b/orm/src/main/java/org/hibernate/tool/internal/reveng/binder/CollectionSecondPass.java @@ -8,6 +8,7 @@ import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.mapping.Collection; import org.hibernate.mapping.DependantValue; +import org.hibernate.mapping.IndexedCollection; import org.hibernate.mapping.OneToMany; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Value; @@ -46,7 +47,8 @@ public void doSecondPass(Map persistentClasses) throws oldKeyForeignKeyName = keyDependantValue.getForeignKeyName(); keyDependantValue.setForeignKeyName("none"); } - super.doSecondPass(persistentClasses); + secondPass(persistentClasses); +// super.doSecondPass(persistentClasses); if(elementDependantValue!=null) { elementDependantValue.setForeignKeyName(oldElementForeignKeyName); } diff --git a/orm/src/main/resources/dao/daohome.ftl b/orm/src/main/resources/dao/daohome.ftl index c79d968365..bf8af5e0c8 100644 --- a/orm/src/main/resources/dao/daohome.ftl +++ b/orm/src/main/resources/dao/daohome.ftl @@ -96,7 +96,7 @@ public class ${declarationName}Home { public void attachDirty(${declarationName} instance) { logger.log(${pojo.importType("java.util.logging.Level")}.INFO, "attaching dirty ${declarationName} instance"); try { - sessionFactory.getCurrentSession().saveOrUpdate(instance); + sessionFactory.getCurrentSession().merge(instance); logger.log(${pojo.importType("java.util.logging.Level")}.INFO, "attach successful"); } catch (RuntimeException re) { @@ -117,14 +117,14 @@ public class ${declarationName}Home { } } - public void delete(${declarationName} persistentInstance) { - logger.log(${pojo.importType("java.util.logging.Level")}.INFO, "deleting ${declarationName} instance"); + public void remove(${declarationName} persistentInstance) { + logger.log(${pojo.importType("java.util.logging.Level")}.INFO, "removing ${declarationName} instance"); try { - sessionFactory.getCurrentSession().delete(persistentInstance); - logger.log(${pojo.importType("java.util.logging.Level")}.INFO, "delete successful"); + sessionFactory.getCurrentSession().remove(persistentInstance); + logger.log(${pojo.importType("java.util.logging.Level")}.INFO, "remove successful"); } catch (RuntimeException re) { - logger.log(${pojo.importType("java.util.logging.Level")}.SEVERE, "delete failed", re); + logger.log(${pojo.importType("java.util.logging.Level")}.SEVERE, "remove failed", re); throw re; } } diff --git a/pom.xml b/pom.xml index 72e07ee131..ef4e1bc6d8 100644 --- a/pom.xml +++ b/pom.xml @@ -93,7 +93,7 @@ 1.19.1 2.2.224 6.0.6.Final - 7.0.0.Alpha3 + 7.0.0.Beta1 2.6.1 8.0.1 3.5.3.Final diff --git a/test/maven/src/it/hbm2dao/src/main/resources/templates/dao/daohome.ftl b/test/maven/src/it/hbm2dao/src/main/resources/templates/dao/daohome.ftl index cab41db76e..a4923b416c 100644 --- a/test/maven/src/it/hbm2dao/src/main/resources/templates/dao/daohome.ftl +++ b/test/maven/src/it/hbm2dao/src/main/resources/templates/dao/daohome.ftl @@ -96,7 +96,7 @@ public class ${declarationName}Home { public void attachDirty(${declarationName} instance) { logger.log(${pojo.importType("java.util.logging.Level")}.INFO, "attaching dirty ${declarationName} instance"); try { - sessionFactory.getCurrentSession().saveOrUpdate(instance); + sessionFactory.getCurrentSession().merge(instance); logger.log(${pojo.importType("java.util.logging.Level")}.INFO, "attach successful"); } catch (RuntimeException re) { @@ -117,14 +117,14 @@ public class ${declarationName}Home { } } - public void delete(${declarationName} persistentInstance) { - logger.log(${pojo.importType("java.util.logging.Level")}.INFO, "deleting ${declarationName} instance"); + public void remove(${declarationName} persistentInstance) { + logger.log(${pojo.importType("java.util.logging.Level")}.INFO, "removing ${declarationName} instance"); try { - sessionFactory.getCurrentSession().delete(persistentInstance); - logger.log(${pojo.importType("java.util.logging.Level")}.INFO, "delete successful"); + sessionFactory.getCurrentSession().remove(persistentInstance); + logger.log(${pojo.importType("java.util.logging.Level")}.INFO, "remove successful"); } catch (RuntimeException re) { - logger.log(${pojo.importType("java.util.logging.Level")}.SEVERE, "delete failed", re); + logger.log(${pojo.importType("java.util.logging.Level")}.SEVERE, "remove failed", re); throw re; } }