HHH-10169 - Add test for issue
This commit is contained in:
parent
3b2157be45
commit
b315c0b949
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.schemaupdate.inheritance;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class CreditCardPayment extends Payment{
|
||||
private String creditCardType;
|
||||
|
||||
public String getCreditCardType() {
|
||||
return creditCardType;
|
||||
}
|
||||
|
||||
public void setCreditCardType(String creditCardType) {
|
||||
this.creditCardType = creditCardType;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0"?>
|
||||
<!--
|
||||
~ Hibernate, Relational Persistence for Idiomatic Java
|
||||
~
|
||||
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
-->
|
||||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
<hibernate-mapping package="org.hibernate.test.schemaupdate.joinedsubclass">
|
||||
<joined-subclass extends="org.hibernate.test.schemaupdate.inheritance.Person" lazy="false" name="org.hibernate.test.schemaupdate.inheritance.Employee" table="EMPLOYEES">
|
||||
<key foreign-key="FK_EMP_PER">
|
||||
<column name="EMP_ID"/>
|
||||
</key>
|
||||
</joined-subclass>
|
||||
</hibernate-mapping>
|
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.schemaupdate.inheritance;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class Employee extends Person implements Serializable {
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.schemaupdate.inheritance;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.boot.spi.MetadataImplementor;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class ForeignKeyNameTest extends BaseUnitTestCase {
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-10169")
|
||||
public void testJoinedSubclassForeignKeyNameIsNotAutoGeneratedWhenProvided() throws Exception {
|
||||
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
|
||||
.applySetting( Environment.HBM2DDL_AUTO, "none" )
|
||||
.build();
|
||||
try {
|
||||
File output = File.createTempFile( "update_script", ".sql" );
|
||||
output.deleteOnExit();
|
||||
|
||||
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
|
||||
.addResource( "org/hibernate/test/schemaupdate/inheritance/Employee.hbm.xml" )
|
||||
.addResource( "org/hibernate/test/schemaupdate/inheritance/Person.hbm.xml" )
|
||||
.addResource( "org/hibernate/test/schemaupdate/inheritance/Manager.hbm.xml" )
|
||||
.addResource( "org/hibernate/test/schemaupdate/inheritance/Payment.hbm.xml" )
|
||||
.buildMetadata();
|
||||
metadata.validate();
|
||||
|
||||
SchemaUpdate su = new SchemaUpdate( ssr, metadata );
|
||||
su.setHaltOnError( true );
|
||||
su.setOutputFile( output.getAbsolutePath() );
|
||||
su.setDelimiter( ";" );
|
||||
su.setFormat( true );
|
||||
su.execute( true, false );
|
||||
|
||||
String fileContent = new String( Files.readAllBytes( output.toPath() ) );
|
||||
assertThat( fileContent.toLowerCase().contains( "fk_emp_per" ), is( true ) );
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( ssr );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubclassForeignKeyNameIsNotAutoGeneratedWhenProvided() throws Exception {
|
||||
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
|
||||
.applySetting( Environment.HBM2DDL_AUTO, "none" )
|
||||
.build();
|
||||
try {
|
||||
File output = File.createTempFile( "update_script", ".sql" );
|
||||
output.deleteOnExit();
|
||||
|
||||
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
|
||||
.addResource( "org/hibernate/test/schemaupdate/inheritance/Payment.hbm.xml" )
|
||||
.buildMetadata();
|
||||
metadata.validate();
|
||||
|
||||
SchemaUpdate su = new SchemaUpdate( ssr, metadata );
|
||||
su.setHaltOnError( true );
|
||||
su.setOutputFile( output.getAbsolutePath() );
|
||||
su.setDelimiter( ";" );
|
||||
su.setFormat( true );
|
||||
su.execute( true, false );
|
||||
|
||||
String fileContent = new String( Files.readAllBytes( output.toPath() ) );
|
||||
assertThat( fileContent.toLowerCase().contains( "fk_cc_pay" ), is( true ) );
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( ssr );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0"?>
|
||||
<!--
|
||||
~ Hibernate, Relational Persistence for Idiomatic Java
|
||||
~
|
||||
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
-->
|
||||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
<hibernate-mapping package="org.hibernate.test.schemaupdate.joinedsubclass">
|
||||
<joined-subclass extends="org.hibernate.test.schemaupdate.inheritance.Person" lazy="false" name="org.hibernate.test.schemaupdate.inheritance.Manager" table="MANAGER">
|
||||
<key>
|
||||
<column name="ID"/>
|
||||
</key>
|
||||
</joined-subclass>
|
||||
</hibernate-mapping>
|
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.schemaupdate.inheritance;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class Manager extends Person implements Serializable {
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0"?>
|
||||
<!--
|
||||
~ Hibernate, Relational Persistence for Idiomatic Java
|
||||
~
|
||||
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
-->
|
||||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
<hibernate-mapping package="org.hibernate.test.schemaupdate.joinedsubclass">
|
||||
<class name="org.hibernate.test.schemaupdate.inheritance.Payment" table="PAYMENT">
|
||||
<id name="id" type="long" column="PAYMENT_ID">
|
||||
<generator class="native"/>
|
||||
</id>
|
||||
<discriminator column="PAYMENT_TYPE" type="string"/>
|
||||
<property name="amount" column="AMOUNT"/>
|
||||
<subclass name="org.hibernate.test.schemaupdate.inheritance.CreditCardPayment" discriminator-value="CREDIT">
|
||||
<join table="CREDIT_PAYMENT">
|
||||
<key column="PAYMENT_ID" foreign-key="FK_CC_PAY"/>
|
||||
<property name="creditCardType" column="CCTYPE"/>
|
||||
</join>
|
||||
</subclass>
|
||||
</class>
|
||||
</hibernate-mapping>
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.schemaupdate.inheritance;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class Payment {
|
||||
private long id;
|
||||
|
||||
private long amount;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public long getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(long amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0"?>
|
||||
<!--
|
||||
~ Hibernate, Relational Persistence for Idiomatic Java
|
||||
~
|
||||
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
-->
|
||||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
<hibernate-mapping package="org.hibernate.test.schemaupdate.joinedsubclass">
|
||||
<class name="org.hibernate.test.schemaupdate.inheritance.Person" table="PERSONS">
|
||||
<id name="id" type="int">
|
||||
<column name="PER_ID"/>
|
||||
<generator class="native"/>
|
||||
</id>
|
||||
<property name="name">
|
||||
<column name="NAME"/>
|
||||
</property>
|
||||
</class>
|
||||
</hibernate-mapping>
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.schemaupdate.inheritance;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class Person implements Serializable {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue