Skip to content

Commit 2137de9

Browse files
committed
HBX-2840 Prevent Hibernate ORM from trying to load component classes
1 parent 251b6e6 commit 2137de9

File tree

5 files changed

+83
-0
lines changed

5 files changed

+83
-0
lines changed

orm/src/main/java/org/hibernate/tool/internal/reveng/util/EnhancedComponent.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,11 @@ public String getIdentifierGeneratorStrategy() {
3838
return genStrategy;
3939
}
4040

41+
@Override
42+
public Class<?> getComponentClass() throws MappingException {
43+
// we prevent ORM from trying to load a component class by name,
44+
// since at the point when we are building these, a corresponding class is not yet created
45+
// (so can't even think about it being compiled and able to load via any classloader) ...
46+
return Object.class;
47+
}
4148
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Hibernate Tools, Tooling for your Hibernate Projects
3+
*
4+
* Copyright 2004-2021 Red Hat, Inc.
5+
*
6+
* Licensed under the GNU Lesser General Public License (LGPL),
7+
* version 2.1 or later (the "License").
8+
* You may not use this file except in compliance with the License.
9+
* You may read the licence in the 'lgpl.txt' file in the root folder of
10+
* project or obtain a copy at
11+
*
12+
* http://www.gnu.org/licenses/lgpl-2.1.html
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" basis,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
package org.hibernate.tool.hbm2x.hbx2840;
21+
22+
import java.io.File;
23+
24+
import org.hibernate.tool.api.export.Exporter;
25+
import org.hibernate.tool.api.export.ExporterConstants;
26+
import org.hibernate.tool.api.export.ExporterFactory;
27+
import org.hibernate.tool.api.export.ExporterType;
28+
import org.hibernate.tool.api.metadata.MetadataDescriptorFactory;
29+
import org.hibernate.tools.test.util.JUnitUtil;
30+
import org.hibernate.tools.test.util.JdbcUtil;
31+
32+
import org.junit.jupiter.api.AfterEach;
33+
import org.junit.jupiter.api.BeforeEach;
34+
import org.junit.jupiter.api.Test;
35+
import org.junit.jupiter.api.io.TempDir;
36+
37+
/**
38+
* Test verifies that a foreign key to a table with a composite ID works.
39+
*/
40+
public class TestCase {
41+
42+
@TempDir
43+
public File outputDir = new File( "output" );
44+
45+
@BeforeEach
46+
void setUp() {
47+
JdbcUtil.createDatabase( this );
48+
Exporter exporter = ExporterFactory.createExporter( ExporterType.JAVA );
49+
exporter.getProperties().put(
50+
ExporterConstants.METADATA_DESCRIPTOR,
51+
MetadataDescriptorFactory.createReverseEngineeringDescriptor( null, null )
52+
);
53+
exporter.getProperties().put( ExporterConstants.DESTINATION_FOLDER, outputDir );
54+
exporter.getProperties().put( ExporterConstants.TEMPLATE_PATH, new String[0] );
55+
exporter.getProperties().setProperty( "ejb3", "true" );
56+
exporter.start();
57+
}
58+
59+
@AfterEach
60+
void tearDown() {
61+
JdbcUtil.dropDatabase( this );
62+
}
63+
64+
@Test
65+
void testFileExistence() {
66+
JUnitUtil.assertIsNonEmptyFile( new File( outputDir.getAbsolutePath() + "/Parent.java" ) );
67+
JUnitUtil.assertIsNonEmptyFile( new File( outputDir.getAbsolutePath() + "/Child.java" ) );
68+
JUnitUtil.assertIsNonEmptyFile( new File( outputDir.getAbsolutePath() + "/ParentId.java" ) );
69+
JUnitUtil.assertIsNonEmptyFile( new File( outputDir.getAbsolutePath() + "/ChildId.java" ) );
70+
}
71+
}

test/common/src/main/java/org/hibernate/tool/test/db/DbTestSuite.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class DbTestSuite {
5353
@Nested public class GenerateFromJDBCWithJavaKeyword extends org.hibernate.tool.hbm2x.GenerateFromJDBCWithJavaKeyword.TestCase {}
5454
@Nested public class IncrementalSchemaReading extends org.hibernate.tool.hbm2x.IncrementalSchemaReading.TestCase {}
5555
@Nested public class JdbcHbm2JavaEjb3 extends org.hibernate.tool.hbm2x.JdbcHbm2JavaEjb3.TestCase {}
56+
@Nested public class HBX2840 extends org.hibernate.tool.hbm2x.hbx2840.TestCase {}
5657
@Nested public class QueryExporterTest extends org.hibernate.tool.hbm2x.query.QueryExporterTest.TestCase {}
5758
@Nested public class HbmLintTest extends org.hibernate.tool.hbmlint.HbmLintTest.TestCase {}
5859
@Nested public class SchemaAnalyzer extends org.hibernate.tool.hbmlint.SchemaAnalyzer.TestCase {}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CREATE TABLE PARENT(ID1_1 INT NOT NULL, ID1_2 INT NOT NULL, PRIMARY KEY (ID1_1, ID1_2));
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));
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DROP TABLE CHILD
2+
DROP TABLE PARENT

0 commit comments

Comments
 (0)