mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-13 14:44:48 +00:00
Fix merge errors
This commit is contained in:
parent
d2865a54df
commit
f836689be8
@ -6,40 +6,54 @@
|
|||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.test.jointable;
|
package org.hibernate.jpa.test.jointable;
|
||||||
|
|
||||||
import org.hibernate.engine.query.spi.HQLQueryPlan;
|
import java.util.LinkedList;
|
||||||
import org.hibernate.hql.spi.QueryTranslator;
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.boot.SessionFactoryBuilder;
|
||||||
|
import org.hibernate.boot.spi.MetadataImplementor;
|
||||||
|
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.SessionFactoryProducer;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Christian Beikov
|
* @author Christian Beikov
|
||||||
*/
|
*/
|
||||||
public class ManyToOneJoinTableTest extends BaseCoreFunctionalTestCase {
|
@DomainModel(
|
||||||
@Override
|
annotatedClasses = {
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
|
||||||
return new Class[] {
|
|
||||||
Person.class,
|
Person.class,
|
||||||
Address.class
|
Address.class
|
||||||
};
|
}
|
||||||
|
)
|
||||||
|
public class ManyToOneJoinTableTest implements SessionFactoryProducer {
|
||||||
|
private SQLStatementInterceptor sqlStatementInterceptor;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SessionFactoryImplementor produceSessionFactory(MetadataImplementor model) {
|
||||||
|
final SessionFactoryBuilder sessionFactoryBuilder = model.getSessionFactoryBuilder();
|
||||||
|
sqlStatementInterceptor = new SQLStatementInterceptor( sessionFactoryBuilder );
|
||||||
|
return (SessionFactoryImplementor) sessionFactoryBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAvoidJoin() {
|
public void testAvoidJoin(SessionFactoryScope scope) {
|
||||||
final HQLQueryPlan plan = sessionFactory().getQueryPlanCache().getHQLQueryPlan(
|
final String queryString = "SELECT e.id FROM Person e";
|
||||||
"SELECT e.id FROM Person e",
|
scope.inTransaction(
|
||||||
false,
|
session -> {
|
||||||
Collections.EMPTY_MAP
|
final LinkedList<String> sqlQueries = sqlStatementInterceptor.getSqlQueries();
|
||||||
);
|
sqlQueries.clear();
|
||||||
assertEquals( 1, plan.getTranslators().length );
|
session.createQuery( queryString ).list();
|
||||||
final QueryTranslator translator = plan.getTranslators()[0];
|
assertThat( sqlQueries.size(), is( 1 ) );
|
||||||
final String generatedSql = translator.getSQLString();
|
|
||||||
// Ideally, we could detect that *ToOne join tables aren't used, but that requires tracking the uses of properties
|
// 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
|
// Since *ToOne join tables are treated like secondary or subclass/superclass tables, the proper fix will allow many more optimizations
|
||||||
assertFalse( generatedSql.contains( "join" ) );
|
assertFalse( sqlQueries.getFirst().contains( "join" ) );
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user