diff --git a/orm/src/main/java/org/hibernate/tool/internal/reveng/util/EnhancedComponent.java b/orm/src/main/java/org/hibernate/tool/internal/reveng/util/EnhancedComponent.java index 1e87499407..e4d5aa03a0 100644 --- a/orm/src/main/java/org/hibernate/tool/internal/reveng/util/EnhancedComponent.java +++ b/orm/src/main/java/org/hibernate/tool/internal/reveng/util/EnhancedComponent.java @@ -38,4 +38,11 @@ public String getIdentifierGeneratorStrategy() { return genStrategy; } + @Override + public Class getComponentClass() throws MappingException { + // we prevent ORM from trying to load a component class by name, + // since at the point when we are building these, a corresponding class is not yet created + // (so can't even think about it being compiled and able to load via any classloader) ... + return Object.class; + } } diff --git a/test/common/src/main/java/org/hibernate/tool/hbm2x/hbx2840/TestCase.java b/test/common/src/main/java/org/hibernate/tool/hbm2x/hbx2840/TestCase.java new file mode 100644 index 0000000000..4ce16a0420 --- /dev/null +++ b/test/common/src/main/java/org/hibernate/tool/hbm2x/hbx2840/TestCase.java @@ -0,0 +1,71 @@ +/* + * Hibernate Tools, Tooling for your Hibernate Projects + * + * Copyright 2004-2021 Red Hat, Inc. + * + * Licensed under the GNU Lesser General Public License (LGPL), + * version 2.1 or later (the "License"). + * You may not use this file except in compliance with the License. + * You may read the licence in the 'lgpl.txt' file in the root folder of + * project or obtain a copy at + * + * http://www.gnu.org/licenses/lgpl-2.1.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hibernate.tool.hbm2x.hbx2840; + +import java.io.File; + +import org.hibernate.tool.api.export.Exporter; +import org.hibernate.tool.api.export.ExporterConstants; +import org.hibernate.tool.api.export.ExporterFactory; +import org.hibernate.tool.api.export.ExporterType; +import org.hibernate.tool.api.metadata.MetadataDescriptorFactory; +import org.hibernate.tools.test.util.JUnitUtil; +import org.hibernate.tools.test.util.JdbcUtil; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +/** + * Test verifies that a foreign key to a table with a composite ID works. + */ +public class TestCase { + + @TempDir + public File outputDir = new File( "output" ); + + @BeforeEach + void setUp() { + JdbcUtil.createDatabase( this ); + Exporter exporter = ExporterFactory.createExporter( ExporterType.JAVA ); + exporter.getProperties().put( + ExporterConstants.METADATA_DESCRIPTOR, + MetadataDescriptorFactory.createReverseEngineeringDescriptor( null, null ) + ); + exporter.getProperties().put( ExporterConstants.DESTINATION_FOLDER, outputDir ); + exporter.getProperties().put( ExporterConstants.TEMPLATE_PATH, new String[0] ); + exporter.getProperties().setProperty( "ejb3", "true" ); + exporter.start(); + } + + @AfterEach + void tearDown() { + JdbcUtil.dropDatabase( this ); + } + + @Test + void testFileExistence() { + JUnitUtil.assertIsNonEmptyFile( new File( outputDir.getAbsolutePath() + "/Parent.java" ) ); + JUnitUtil.assertIsNonEmptyFile( new File( outputDir.getAbsolutePath() + "/Child.java" ) ); + JUnitUtil.assertIsNonEmptyFile( new File( outputDir.getAbsolutePath() + "/ParentId.java" ) ); + JUnitUtil.assertIsNonEmptyFile( new File( outputDir.getAbsolutePath() + "/ChildId.java" ) ); + } +} diff --git a/test/common/src/main/java/org/hibernate/tool/test/db/DbTestSuite.java b/test/common/src/main/java/org/hibernate/tool/test/db/DbTestSuite.java index c3d24bb19e..d9ef06619b 100644 --- a/test/common/src/main/java/org/hibernate/tool/test/db/DbTestSuite.java +++ b/test/common/src/main/java/org/hibernate/tool/test/db/DbTestSuite.java @@ -53,6 +53,7 @@ public class DbTestSuite { @Nested public class GenerateFromJDBCWithJavaKeyword extends org.hibernate.tool.hbm2x.GenerateFromJDBCWithJavaKeyword.TestCase {} @Nested public class IncrementalSchemaReading extends org.hibernate.tool.hbm2x.IncrementalSchemaReading.TestCase {} @Nested public class JdbcHbm2JavaEjb3 extends org.hibernate.tool.hbm2x.JdbcHbm2JavaEjb3.TestCase {} + @Nested public class HBX2840 extends org.hibernate.tool.hbm2x.hbx2840.TestCase {} @Nested public class QueryExporterTest extends org.hibernate.tool.hbm2x.query.QueryExporterTest.TestCase {} @Nested public class HbmLintTest extends org.hibernate.tool.hbmlint.HbmLintTest.TestCase {} @Nested public class SchemaAnalyzer extends org.hibernate.tool.hbmlint.SchemaAnalyzer.TestCase {} diff --git a/test/common/src/main/resources/org/hibernate/tool/hbm2x/hbx2840/create.sql b/test/common/src/main/resources/org/hibernate/tool/hbm2x/hbx2840/create.sql new file mode 100644 index 0000000000..dfa89c5a98 --- /dev/null +++ b/test/common/src/main/resources/org/hibernate/tool/hbm2x/hbx2840/create.sql @@ -0,0 +1,2 @@ +CREATE TABLE PARENT(ID1_1 INT NOT NULL, ID1_2 INT NOT NULL, PRIMARY KEY (ID1_1, ID1_2)); +CREATE TABLE CHILD (ID2_1 INT NOT NULL, ID2_2 INT NOT NULL, PRIMARY KEY (ID2_1, ID2_2), FOREIGN KEY (ID2_1, ID2_2) REFERENCES PARENT (ID1_1, ID1_2)); diff --git a/test/common/src/main/resources/org/hibernate/tool/hbm2x/hbx2840/drop.sql b/test/common/src/main/resources/org/hibernate/tool/hbm2x/hbx2840/drop.sql new file mode 100644 index 0000000000..6136bd4e90 --- /dev/null +++ b/test/common/src/main/resources/org/hibernate/tool/hbm2x/hbx2840/drop.sql @@ -0,0 +1,2 @@ +DROP TABLE CHILD +DROP TABLE PARENT