Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.hibernate.tool.api.reveng.TableIdentifier;
import org.hibernate.tool.internal.reveng.RevengMetadataCollector;
import org.hibernate.tool.internal.reveng.binder.ForeignKeyUtils.ForeignKeyForColumns;
import org.hibernate.tool.internal.reveng.util.EnhancedComponent;
import org.hibernate.tool.internal.reveng.util.RevengUtils;

class PrimaryKeyBinder extends AbstractBinder {
Expand Down Expand Up @@ -194,7 +195,7 @@ private SimpleValue handleCompositeKey(
PersistentClass rc,
Set<Column> processedColumns,
List<Column> keyColumns) {
Component result = new Component(getMetadataBuildingContext(), rc);
Component result = new EnhancedComponent(getMetadataBuildingContext(), rc);
result.setMetaAttributes(Collections.EMPTY_MAP);
result.setEmbedded(false);
result.setComponentClassName(getCompositeIdName(rc));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.hibernate.tool.internal.reveng.util;

import java.util.Properties;

import org.hibernate.MappingException;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.mapping.Component;
import org.hibernate.mapping.PersistentClass;

@SuppressWarnings("serial")
public class EnhancedComponent extends Component {

public EnhancedComponent(MetadataBuildingContext metadata, PersistentClass owner) throws MappingException {
super(metadata, owner);
}

@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;
}
}
Original file line number Diff line number Diff line change
@@ -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" ) );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DROP TABLE CHILD
DROP TABLE PARENT