HHH-13769: Avoid unnecessary joins test
This commit is contained in:
parent
31913eaeea
commit
3eed218135
|
@ -21,6 +21,7 @@ import javax.persistence.Table;
|
|||
import org.hibernate.boot.spi.MetadataImplementor;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.FailureExpected;
|
||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
|
@ -49,10 +50,13 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
public class TablePerClassTest {
|
||||
|
||||
@Test
|
||||
@FailureExpected(reason = "@AttributeOverrides not applied for Table per class")
|
||||
public void testSchema(SessionFactoryScope scope) {
|
||||
MetadataImplementor metadata = scope.getMetadataImplementor();
|
||||
assertTrue( SchemaUtil.isColumnPresent( "DOMESTIC_CUSTOMER", "DC_address_street", metadata ) );
|
||||
assertTrue( SchemaUtil.isColumnPresent( "CUSTOMER", "STREET", metadata ) );
|
||||
assertTrue( SchemaUtil.isColumnPresent( "FOREIGN_CUSTOMER", "STREET", metadata ) );
|
||||
assertTrue( SchemaUtil.isColumnPresent( "DOMESTIC_CUSTOMER", "DC_name", metadata ) );
|
||||
assertTrue( SchemaUtil.isColumnPresent( "DOMESTIC_CUSTOMER", "DC_address_street", metadata ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -153,7 +157,8 @@ public class TablePerClassTest {
|
|||
|
||||
@Entity(name = "Customer")
|
||||
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
|
||||
public static abstract class Customer {
|
||||
@Table(name = "CUSTOMER")
|
||||
public static class Customer {
|
||||
private Integer id;
|
||||
private String name;
|
||||
private Address address;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* 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.jpa.test.jointable;
|
||||
package org.hibernate.orm.test.jpa.jointable;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
|
@ -4,19 +4,22 @@
|
|||
* 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.jpa.test.jointable;
|
||||
package org.hibernate.orm.test.jpa.jointable;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.hibernate.boot.SessionFactoryBuilder;
|
||||
import org.hibernate.boot.spi.MetadataImplementor;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
|
||||
import org.hibernate.testing.jdbc.SQLStatementInterceptor;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryProducer;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
@ -31,6 +34,12 @@ import static org.junit.Assert.assertThat;
|
|||
Address.class
|
||||
}
|
||||
)
|
||||
@ServiceRegistry(
|
||||
settings = {
|
||||
@ServiceRegistry.Setting(name = AvailableSettings.HBM2DDL_DATABASE_ACTION, value = "create-drop")
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
public class ManyToOneJoinTableTest implements SessionFactoryProducer {
|
||||
private SQLStatementInterceptor sqlStatementInterceptor;
|
||||
|
||||
|
@ -52,7 +61,11 @@ public class ManyToOneJoinTableTest implements SessionFactoryProducer {
|
|||
assertThat( sqlQueries.size(), is( 1 ) );
|
||||
// Ideally, we could detect that *ToOne join tables aren't used, but that requires tracking the uses of properties
|
||||
// Since *ToOne join tables are treated like secondary or subclass/superclass tables, the proper fix will allow many more optimizations
|
||||
assertFalse( sqlQueries.getFirst().contains( "join" ) );
|
||||
String generatedSQl = sqlQueries.getFirst();
|
||||
assertFalse(
|
||||
"The generated sql contains a useless join: " + generatedSQl,
|
||||
generatedSQl.contains( "join" )
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
|
@ -4,10 +4,14 @@
|
|||
* 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.jpa.test.jointable;
|
||||
package org.hibernate.orm.test.jpa.jointable;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Set;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
|
||||
/**
|
||||
*
|
|
@ -26,7 +26,6 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
|
|||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.engine.spi.Status;
|
||||
import org.hibernate.stat.Statistics;
|
||||
import org.hibernate.tool.schema.Action;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.jdbc.SQLStatementInterceptor;
|
||||
|
|
Loading…
Reference in New Issue