HHH-17460 - Ongoing JPA 32 work
This commit is contained in:
parent
76b2719fed
commit
edf2bd4ecf
|
@ -964,7 +964,7 @@
|
||||||
<xs:attribute name="embed-xml" type="xs:boolean"/>
|
<xs:attribute name="embed-xml" type="xs:boolean"/>
|
||||||
<xs:attribute name="entity-name" type="xs:string"/>
|
<xs:attribute name="entity-name" type="xs:string"/>
|
||||||
<xs:attribute name="node" type="xs:string"/>
|
<xs:attribute name="node" type="xs:string"/>
|
||||||
<xs:attribute name="not-found" default="exception" type="NotFoundEnum"/>
|
<xs:attribute name="not-found" type="NotFoundEnum"/>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
|
|
||||||
<xs:complexType name="OneToOneType">
|
<xs:complexType name="OneToOneType">
|
||||||
|
@ -1014,7 +1014,7 @@
|
||||||
<xs:attribute name="lazy" type="LazyWithNoProxyEnum"/>
|
<xs:attribute name="lazy" type="LazyWithNoProxyEnum"/>
|
||||||
<xs:attribute name="name" use="required" type="xs:string"/>
|
<xs:attribute name="name" use="required" type="xs:string"/>
|
||||||
<xs:attribute name="node" type="xs:string"/>
|
<xs:attribute name="node" type="xs:string"/>
|
||||||
<xs:attribute name="not-found" default="exception" type="NotFoundEnum"/>
|
<xs:attribute name="not-found" type="NotFoundEnum"/>
|
||||||
<xs:attribute name="not-null" type="xs:boolean"/>
|
<xs:attribute name="not-null" type="xs:boolean"/>
|
||||||
<xs:attribute name="optimistic-lock" default="true" type="xs:boolean"/>
|
<xs:attribute name="optimistic-lock" default="true" type="xs:boolean"/>
|
||||||
<!-- only supported for properties of a class (not component) -->
|
<!-- only supported for properties of a class (not component) -->
|
||||||
|
@ -1046,7 +1046,7 @@
|
||||||
<xs:attribute name="formula" type="xs:string"/>
|
<xs:attribute name="formula" type="xs:string"/>
|
||||||
<xs:attribute name="lazy" type="LazyEnum"/>
|
<xs:attribute name="lazy" type="LazyEnum"/>
|
||||||
<xs:attribute name="node" type="xs:string"/>
|
<xs:attribute name="node" type="xs:string"/>
|
||||||
<xs:attribute name="not-found" default="exception" type="NotFoundEnum"/>
|
<xs:attribute name="not-found" type="NotFoundEnum"/>
|
||||||
<xs:attribute name="order-by" type="xs:string"/>
|
<xs:attribute name="order-by" type="xs:string"/>
|
||||||
<xs:attribute name="outer-join" type="OuterJoinEnum"/>
|
<xs:attribute name="outer-join" type="OuterJoinEnum"/>
|
||||||
<xs:attribute name="property-ref" type="xs:string"/>
|
<xs:attribute name="property-ref" type="xs:string"/>
|
||||||
|
|
|
@ -1620,7 +1620,7 @@
|
||||||
<xsd:attribute name="mapped-by" type="xsd:string"/>
|
<xsd:attribute name="mapped-by" type="xsd:string"/>
|
||||||
<xsd:attribute name="orphan-removal" type="xsd:boolean"/>
|
<xsd:attribute name="orphan-removal" type="xsd:boolean"/>
|
||||||
<xsd:attribute name="classification" type="orm:limited-collection-classification-enum" />
|
<xsd:attribute name="classification" type="orm:limited-collection-classification-enum" />
|
||||||
<xsd:attribute name="not-found" default="EXCEPTION" type="orm:not-found-enum"/>
|
<xsd:attribute name="not-found" type="orm:not-found-enum"/>
|
||||||
<xsd:attribute name="optimistic-lock" type="xsd:boolean" default="true" />
|
<xsd:attribute name="optimistic-lock" type="xsd:boolean" default="true" />
|
||||||
</xsd:complexType>
|
</xsd:complexType>
|
||||||
|
|
||||||
|
@ -1665,7 +1665,7 @@
|
||||||
<xsd:attribute name="optimistic-lock" type="xsd:boolean" default="true" />
|
<xsd:attribute name="optimistic-lock" type="xsd:boolean" default="true" />
|
||||||
<xsd:attribute name="maps-id" type="xsd:string"/>
|
<xsd:attribute name="maps-id" type="xsd:string"/>
|
||||||
<xsd:attribute name="id" type="xsd:boolean"/>
|
<xsd:attribute name="id" type="xsd:boolean"/>
|
||||||
<xsd:attribute name="not-found" default="EXCEPTION" type="orm:not-found-enum"/>
|
<xsd:attribute name="not-found" type="orm:not-found-enum"/>
|
||||||
</xsd:complexType>
|
</xsd:complexType>
|
||||||
|
|
||||||
<!-- **************************************************** -->
|
<!-- **************************************************** -->
|
||||||
|
@ -2046,7 +2046,7 @@
|
||||||
<xsd:attribute name="mapped-by" type="xsd:string"/>
|
<xsd:attribute name="mapped-by" type="xsd:string"/>
|
||||||
<xsd:attribute name="orphan-removal" type="xsd:boolean"/>
|
<xsd:attribute name="orphan-removal" type="xsd:boolean"/>
|
||||||
<xsd:attribute name="classification" type="orm:limited-collection-classification-enum" />
|
<xsd:attribute name="classification" type="orm:limited-collection-classification-enum" />
|
||||||
<xsd:attribute name="not-found" default="EXCEPTION" type="orm:not-found-enum"/>
|
<xsd:attribute name="not-found" type="orm:not-found-enum"/>
|
||||||
<xsd:attribute name="optimistic-lock" type="xsd:boolean" default="true" />
|
<xsd:attribute name="optimistic-lock" type="xsd:boolean" default="true" />
|
||||||
</xsd:complexType>
|
</xsd:complexType>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package org.hibernate.orm.test.schemaupdate.foreignkeys;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Customer {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
List<CustomerInventory> inventory;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CustomerInventory> getInventory() {
|
||||||
|
return inventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInventory(List<CustomerInventory> inventory) {
|
||||||
|
this.inventory = inventory;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package org.hibernate.orm.test.schemaupdate.foreignkeys;
|
||||||
|
|
||||||
|
public class CustomerInventory {
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
private Customer customer;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Customer getCustomer() {
|
||||||
|
return customer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCustomer(Customer customer) {
|
||||||
|
this.customer = customer;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
package org.hibernate.orm.test.schemaupdate.foreignkeys;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
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.dialect.H2Dialect;
|
||||||
|
import org.hibernate.tool.hbm2ddl.SchemaExport;
|
||||||
|
import org.hibernate.tool.schema.TargetType;
|
||||||
|
|
||||||
|
import org.hibernate.testing.orm.junit.BaseUnitTest;
|
||||||
|
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||||
|
import org.hibernate.testing.util.ServiceRegistryUtil;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
@BaseUnitTest
|
||||||
|
@RequiresDialect(H2Dialect.class)
|
||||||
|
public class ForeignKeysCreationForXMLMappingTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testForeignKeyCreation() throws Exception {
|
||||||
|
File output = File.createTempFile( "person_fk_script", ".sql" );
|
||||||
|
output.deleteOnExit();
|
||||||
|
StandardServiceRegistry ssr = ServiceRegistryUtil.serviceRegistry();
|
||||||
|
try {
|
||||||
|
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
|
||||||
|
.addResource( "org/hibernate/orm/test/schemaupdate/foreignkeys/customer.orm.xml" )
|
||||||
|
.buildMetadata();
|
||||||
|
metadata.validate();
|
||||||
|
|
||||||
|
new SchemaExport().setOutputFile( output.getAbsolutePath() ).createOnly(
|
||||||
|
EnumSet.of( TargetType.SCRIPT ),
|
||||||
|
metadata
|
||||||
|
);
|
||||||
|
|
||||||
|
final List<String> sqlLines = Files.readAllLines( output.toPath(), Charset.defaultCharset() );
|
||||||
|
assertThat( sqlLines.size() ).isNotEqualTo( 0 );
|
||||||
|
assertTrue( checkFKCreation( sqlLines ), "Foreign keys have not been created" );
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
StandardServiceRegistryBuilder.destroy( ssr );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkFKCreation(List<String> sqlLines) {
|
||||||
|
for ( String sql : sqlLines ) {
|
||||||
|
if ( sql.contains( "foreign key" ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!--
|
||||||
|
~ 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>.
|
||||||
|
-->
|
||||||
|
<entity-mappings
|
||||||
|
xmlns="http://java.sun.com/xml/ns/persistence/orm"
|
||||||
|
version="2.0">
|
||||||
|
<package>org.hibernate.orm.test.schemaupdate.foreignkeys</package>
|
||||||
|
|
||||||
|
<entity class="Customer">
|
||||||
|
<attributes>
|
||||||
|
<id name="id"/>
|
||||||
|
<basic name="name"/>
|
||||||
|
<one-to-many name="inventory" mapped-by="customer" fetch="EAGER"/>
|
||||||
|
</attributes>
|
||||||
|
</entity>
|
||||||
|
<entity class="CustomerInventory">
|
||||||
|
<attributes>
|
||||||
|
<id name="id"/>
|
||||||
|
<basic name="name"/>
|
||||||
|
<many-to-one name="customer" fetch="EAGER">
|
||||||
|
<join-column name="CI_CUSTOMERID" insertable="false" nullable="false"/>
|
||||||
|
</many-to-one>
|
||||||
|
|
||||||
|
</attributes>
|
||||||
|
</entity>
|
||||||
|
</entity-mappings>
|
Loading…
Reference in New Issue