Fix compilation errors after merge
This commit is contained in:
parent
f77fb75639
commit
eb43734658
|
@ -4,10 +4,9 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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.io.Serializable;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import javax.persistence.Embeddable;
|
import javax.persistence.Embeddable;
|
||||||
import javax.persistence.EmbeddedId;
|
import javax.persistence.EmbeddedId;
|
||||||
|
@ -20,57 +19,55 @@ import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.NamedQuery;
|
import javax.persistence.NamedQuery;
|
||||||
import javax.persistence.SecondaryTable;
|
import javax.persistence.SecondaryTable;
|
||||||
|
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.boot.SessionFactoryBuilder;
|
||||||
import org.hibernate.engine.query.spi.HQLQueryPlan;
|
import org.hibernate.boot.spi.MetadataImplementor;
|
||||||
import org.hibernate.hql.spi.QueryTranslator;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.jdbc.SQLStatementInterceptor;
|
||||||
import org.junit.Test;
|
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 org.junit.jupiter.api.Test;
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Christian Beikov
|
* @author Christian Beikov
|
||||||
*/
|
*/
|
||||||
public class ManyToOneJoinTableTest extends BaseCoreFunctionalTestCase {
|
@DomainModel(
|
||||||
@Override
|
annotatedClasses = {
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
ManyToOneJoinTableTest.ResourceImpl.class,
|
||||||
return new Class[] {
|
ManyToOneJoinTableTest.IssuerImpl.class
|
||||||
Person.class,
|
|
||||||
Address.class,
|
|
||||||
ResourceImpl.class,
|
|
||||||
IssuerImpl.class
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
@ServiceRegistry(
|
||||||
|
settings = {
|
||||||
|
@ServiceRegistry.Setting(name = AvailableSettings.HBM2DDL_DATABASE_ACTION, value = "create-drop")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@SessionFactory
|
||||||
|
public class ManyToOneJoinTableTest implements SessionFactoryProducer {
|
||||||
|
private SQLStatementInterceptor sqlStatementInterceptor;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure(Configuration configuration) {
|
public SessionFactoryImplementor produceSessionFactory(MetadataImplementor model) {
|
||||||
super.configure( configuration );
|
final SessionFactoryBuilder sessionFactoryBuilder = model.getSessionFactoryBuilder();
|
||||||
// configuration.setProperty(AvailableSettings.OMIT_JOIN_OF_SUPERCLASS_TABLES, Boolean.FALSE.toString());
|
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
|
@Test
|
||||||
public void testRegression() {
|
public void testRegression(SessionFactoryScope scope) {
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
scope.inTransaction(
|
||||||
|
session -> {
|
||||||
session.createNamedQuery( IssuerImpl.SELECT_RESOURCES_BY_ISSUER )
|
session.createNamedQuery( IssuerImpl.SELECT_RESOURCES_BY_ISSUER )
|
||||||
.setParameter( "issuer", session.getReference( IssuerImpl.class, new Identifier( 1l, "ABC" ) ) )
|
.setParameter(
|
||||||
|
"issuer",
|
||||||
|
session.getReference( IssuerImpl.class, new Identifier( 1l, "ABC" ) )
|
||||||
|
)
|
||||||
.getResultList();
|
.getResultList();
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
@ -183,6 +180,4 @@ public class ManyToOneJoinTableTest extends BaseCoreFunctionalTestCase {
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -11,6 +11,7 @@ import javax.persistence.JoinColumn;
|
||||||
|
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
|
import org.hibernate.engine.jdbc.Size;
|
||||||
import org.hibernate.engine.spi.Mapping;
|
import org.hibernate.engine.spi.Mapping;
|
||||||
import org.hibernate.envers.internal.EnversMessageLogger;
|
import org.hibernate.envers.internal.EnversMessageLogger;
|
||||||
import org.hibernate.envers.internal.tools.StringTools;
|
import org.hibernate.envers.internal.tools.StringTools;
|
||||||
|
@ -347,7 +348,11 @@ public final class MetadataTools {
|
||||||
String columnDefinition = column.getSqlType();
|
String columnDefinition = column.getSqlType();
|
||||||
if ( !StringTools.isEmpty( columnDefinition ) ) {
|
if ( !StringTools.isEmpty( columnDefinition ) ) {
|
||||||
final int sqlTypeCode = column.getSqlTypeCode( mapping );
|
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(
|
LOG.infof(
|
||||||
"Column [%s] uses a column-definition of [%s], resolved sql-type as [%s].",
|
"Column [%s] uses a column-definition of [%s], resolved sql-type as [%s].",
|
||||||
column.getName(),
|
column.getName(),
|
||||||
|
|
|
@ -24,9 +24,9 @@ import org.hibernate.testing.RequiresDialect;
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
|
||||||
import static org.hibernate.boot.model.naming.Identifier.toIdentifier;
|
import static org.hibernate.boot.model.naming.Identifier.toIdentifier;
|
||||||
import static org.hibernate.mapping.Column.DEFAULT_LENGTH;
|
import static org.hibernate.engine.jdbc.Size.DEFAULT_LENGTH;
|
||||||
import static org.hibernate.mapping.Column.DEFAULT_PRECISION;
|
import static org.hibernate.engine.jdbc.Size.DEFAULT_PRECISION;
|
||||||
import static org.hibernate.mapping.Column.DEFAULT_SCALE;
|
import static org.hibernate.engine.jdbc.Size.DEFAULT_SCALE;
|
||||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
@ -57,19 +57,23 @@ public class BasicTypeColumnDefinitionTest extends BaseEnversJPAFunctionalTestCa
|
||||||
@Test
|
@Test
|
||||||
@Priority(10)
|
@Priority(10)
|
||||||
public void testMetadataBindings() {
|
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 Table auditTable = metadata().getEntityBinding( BasicTypeContainer.class.getName() + "_AUD" ).getTable();
|
||||||
|
|
||||||
final org.hibernate.mapping.Column caseNumber = auditTable.getColumn( toIdentifier( "caseNumber" ) );
|
final org.hibernate.mapping.Column caseNumber = auditTable.getColumn( toIdentifier( "caseNumber" ) );
|
||||||
assertEquals( "integer", caseNumber.getSqlType() );
|
assertEquals( "integer", caseNumber.getSqlType() );
|
||||||
assertEquals( DEFAULT_LENGTH, caseNumber.getLength() );
|
assertEquals( expectedDefaultLength, caseNumber.getLength() );
|
||||||
assertEquals( DEFAULT_PRECISION, caseNumber.getPrecision() );
|
assertEquals( expectedDefaultPrecision, caseNumber.getPrecision() );
|
||||||
assertEquals( DEFAULT_SCALE, caseNumber.getScale() );
|
assertEquals( expectedDefaultScale, caseNumber.getScale() );
|
||||||
|
|
||||||
final org.hibernate.mapping.Column colDef = auditTable.getColumn( toIdentifier( "columnWithDefinition" ) );
|
final org.hibernate.mapping.Column colDef = auditTable.getColumn( toIdentifier( "columnWithDefinition" ) );
|
||||||
assertEquals( "varchar(10)", colDef.getSqlType() );
|
assertEquals( "varchar(10)", colDef.getSqlType() );
|
||||||
assertEquals( 10, colDef.getLength() );
|
assertEquals( new Long( 10 ), colDef.getLength() );
|
||||||
assertEquals( DEFAULT_PRECISION, colDef.getPrecision() );
|
assertEquals( expectedDefaultPrecision, colDef.getPrecision() );
|
||||||
assertEquals( DEFAULT_SCALE, colDef.getScale() );
|
assertEquals( expectedDefaultScale, colDef.getScale() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue