Fix compilation errors after merge

This commit is contained in:
Andrea Boriero 2020-02-05 12:16:41 +00:00
parent f77fb75639
commit eb43734658
3 changed files with 59 additions and 55 deletions

View File

@ -4,10 +4,9 @@
* 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.jpa.test.joinable;
import java.io.Serializable;
import java.util.Collections;
import java.util.Objects;
import javax.persistence.Embeddable;
import javax.persistence.EmbeddedId;
@ -20,59 +19,57 @@ import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.SecondaryTable;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.query.spi.HQLQueryPlan;
import org.hibernate.hql.spi.QueryTranslator;
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.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
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 static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.junit.jupiter.api.Test;
/**
* @author Christian Beikov
*/
public class ManyToOneJoinTableTest extends BaseCoreFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Person.class,
Address.class,
ResourceImpl.class,
IssuerImpl.class
};
}
@DomainModel(
annotatedClasses = {
ManyToOneJoinTableTest.ResourceImpl.class,
ManyToOneJoinTableTest.IssuerImpl.class
}
)
@ServiceRegistry(
settings = {
@ServiceRegistry.Setting(name = AvailableSettings.HBM2DDL_DATABASE_ACTION, value = "create-drop")
}
)
@SessionFactory
public class ManyToOneJoinTableTest implements SessionFactoryProducer {
private SQLStatementInterceptor sqlStatementInterceptor;
@Override
protected void configure(Configuration configuration) {
super.configure( configuration );
// configuration.setProperty(AvailableSettings.OMIT_JOIN_OF_SUPERCLASS_TABLES, Boolean.FALSE.toString());
public SessionFactoryImplementor produceSessionFactory(MetadataImplementor model) {
final SessionFactoryBuilder sessionFactoryBuilder = model.getSessionFactoryBuilder();
sqlStatementInterceptor = new SQLStatementInterceptor( sessionFactoryBuilder );
return (SessionFactoryImplementor) sessionFactoryBuilder.build();
}
@Test
public void testAvoidJoin() {
final HQLQueryPlan plan = sessionFactory().getQueryPlanCache().getHQLQueryPlan(
"SELECT e.id FROM Person e",
false,
Collections.EMPTY_MAP
);
assertEquals( 1, plan.getTranslators().length );
final QueryTranslator translator = plan.getTranslators()[0];
final String generatedSql = translator.getSQLString();
// 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( generatedSql.contains( "join" ) );
}
@Test
public void testRegression() {
doInHibernate( this::sessionFactory, session -> {
session.createNamedQuery( IssuerImpl.SELECT_RESOURCES_BY_ISSUER )
.setParameter( "issuer", session.getReference( IssuerImpl.class, new Identifier( 1l, "ABC" ) ) )
.getResultList();
} );
public void testRegression(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
session.createNamedQuery( IssuerImpl.SELECT_RESOURCES_BY_ISSUER )
.setParameter(
"issuer",
session.getReference( IssuerImpl.class, new Identifier( 1l, "ABC" ) )
)
.getResultList();
} );
}
public interface Issuer extends Resource {
@ -183,6 +180,4 @@ public class ManyToOneJoinTableTest extends BaseCoreFunctionalTestCase {
this.identifier = identifier;
}
}
}

View File

@ -11,6 +11,7 @@ import javax.persistence.JoinColumn;
import org.hibernate.boot.Metadata;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.Size;
import org.hibernate.engine.spi.Mapping;
import org.hibernate.envers.internal.EnversMessageLogger;
import org.hibernate.envers.internal.tools.StringTools;
@ -347,7 +348,11 @@ public final class MetadataTools {
String columnDefinition = column.getSqlType();
if ( !StringTools.isEmpty( columnDefinition ) ) {
final int sqlTypeCode = column.getSqlTypeCode( mapping );
final String sqlType = dialect.getTypeName( sqlTypeCode, column.getLength(), column.getPrecision(), column.getScale() );
final Size size = new Size()
.setLength( column.getLength() )
.setPrecision( column.getPrecision() )
.setScale( column.getScale() );
final String sqlType = dialect.getTypeName( sqlTypeCode, size );
LOG.infof(
"Column [%s] uses a column-definition of [%s], resolved sql-type as [%s].",
column.getName(),

View File

@ -24,9 +24,9 @@ import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue;
import static org.hibernate.boot.model.naming.Identifier.toIdentifier;
import static org.hibernate.mapping.Column.DEFAULT_LENGTH;
import static org.hibernate.mapping.Column.DEFAULT_PRECISION;
import static org.hibernate.mapping.Column.DEFAULT_SCALE;
import static org.hibernate.engine.jdbc.Size.DEFAULT_LENGTH;
import static org.hibernate.engine.jdbc.Size.DEFAULT_PRECISION;
import static org.hibernate.engine.jdbc.Size.DEFAULT_SCALE;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
@ -57,19 +57,23 @@ public class BasicTypeColumnDefinitionTest extends BaseEnversJPAFunctionalTestCa
@Test
@Priority(10)
public void testMetadataBindings() {
final Long expectedDefaultLength = new Long( DEFAULT_LENGTH );
final Long expectedDefaultPrecision = new Long( DEFAULT_PRECISION );
final Long expectedDefaultScale = new Long( DEFAULT_SCALE );
final Table auditTable = metadata().getEntityBinding( BasicTypeContainer.class.getName() + "_AUD" ).getTable();
final org.hibernate.mapping.Column caseNumber = auditTable.getColumn( toIdentifier( "caseNumber" ) );
assertEquals( "integer", caseNumber.getSqlType() );
assertEquals( DEFAULT_LENGTH, caseNumber.getLength() );
assertEquals( DEFAULT_PRECISION, caseNumber.getPrecision() );
assertEquals( DEFAULT_SCALE, caseNumber.getScale() );
assertEquals( expectedDefaultLength, caseNumber.getLength() );
assertEquals( expectedDefaultPrecision, caseNumber.getPrecision() );
assertEquals( expectedDefaultScale, caseNumber.getScale() );
final org.hibernate.mapping.Column colDef = auditTable.getColumn( toIdentifier( "columnWithDefinition" ) );
assertEquals( "varchar(10)", colDef.getSqlType() );
assertEquals( 10, colDef.getLength() );
assertEquals( DEFAULT_PRECISION, colDef.getPrecision() );
assertEquals( DEFAULT_SCALE, colDef.getScale() );
assertEquals( new Long( 10 ), colDef.getLength() );
assertEquals( expectedDefaultPrecision, colDef.getPrecision() );
assertEquals( expectedDefaultScale, colDef.getScale() );
}
@Test