Fix resolveMappingExpressable for SqmFieldLiteral
This commit is contained in:
parent
118b160b02
commit
f3ff509095
|
@ -66,6 +66,7 @@ import org.hibernate.persister.spi.PersisterFactory;
|
||||||
import org.hibernate.query.NavigablePath;
|
import org.hibernate.query.NavigablePath;
|
||||||
import org.hibernate.query.sqm.SqmExpressable;
|
import org.hibernate.query.sqm.SqmExpressable;
|
||||||
import org.hibernate.query.sqm.tree.domain.SqmPath;
|
import org.hibernate.query.sqm.tree.domain.SqmPath;
|
||||||
|
import org.hibernate.query.sqm.tree.expression.SqmFieldLiteral;
|
||||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||||
import org.hibernate.type.BasicType;
|
import org.hibernate.type.BasicType;
|
||||||
import org.hibernate.type.Type;
|
import org.hibernate.type.Type;
|
||||||
|
@ -741,6 +742,10 @@ public class MappingMetamodelImpl implements MappingMetamodel, MetamodelImplemen
|
||||||
return getTypeConfiguration().getBasicTypeForJavaType(((BasicSqmPathSource<?>) sqmExpressable).getJavaType());
|
return getTypeConfiguration().getBasicTypeForJavaType(((BasicSqmPathSource<?>) sqmExpressable).getJavaType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( sqmExpressable instanceof SqmFieldLiteral ) {
|
||||||
|
return getTypeConfiguration().getBasicTypeForJavaType( ( (SqmFieldLiteral<?>) sqmExpressable ).getJavaType() );
|
||||||
|
}
|
||||||
|
|
||||||
if ( sqmExpressable instanceof CompositeSqmPathSource ) {
|
if ( sqmExpressable instanceof CompositeSqmPathSource ) {
|
||||||
throw new NotYetImplementedFor6Exception( "Resolution of embedded-valued SqmExpressable nodes not yet implemented" );
|
throw new NotYetImplementedFor6Exception( "Resolution of embedded-valued SqmExpressable nodes not yet implemented" );
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,94 @@
|
||||||
|
/*
|
||||||
|
* 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>.
|
||||||
|
*/
|
||||||
|
package org.hibernate.orm.test.typedescriptor;
|
||||||
|
|
||||||
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||||
|
*/
|
||||||
|
@DomainModel(
|
||||||
|
annotatedClasses = VariousTypesEntity.class
|
||||||
|
)
|
||||||
|
@SessionFactory
|
||||||
|
public class ByteTest {
|
||||||
|
public static final byte TEST_VALUE = 65;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setUp(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
session -> {
|
||||||
|
VariousTypesEntity entity = new VariousTypesEntity();
|
||||||
|
entity.setId( 1 );
|
||||||
|
entity.setByteData( TEST_VALUE );
|
||||||
|
session.persist( entity );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void tearDown(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
session ->
|
||||||
|
session.createQuery( "delete from VariousTypesEntity" ).executeUpdate()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue(jiraKey = "HHH-6533")
|
||||||
|
public void testByteDataPersistenceAndRetrieval(SessionFactoryScope scope) {
|
||||||
|
|
||||||
|
scope.inTransaction(
|
||||||
|
session -> {
|
||||||
|
VariousTypesEntity entity = (VariousTypesEntity) session.createQuery(
|
||||||
|
" from VariousTypesEntity " +
|
||||||
|
" where byteData = org.hibernate.orm.test.typedescriptor.ByteTest.TEST_VALUE "
|
||||||
|
).uniqueResult();
|
||||||
|
|
||||||
|
assertNotNull( entity );
|
||||||
|
assertEquals( TEST_VALUE, entity.getByteData() );
|
||||||
|
entity.setByteData( Byte.MIN_VALUE );
|
||||||
|
session.update( entity );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Testing minimal value.
|
||||||
|
scope.inTransaction(
|
||||||
|
session -> {
|
||||||
|
VariousTypesEntity entity = (VariousTypesEntity) session.createQuery(
|
||||||
|
" from VariousTypesEntity " +
|
||||||
|
" where byteData = java.lang.Byte.MIN_VALUE "
|
||||||
|
).uniqueResult();
|
||||||
|
assertNotNull( entity );
|
||||||
|
assertEquals( Byte.MIN_VALUE, entity.getByteData() );
|
||||||
|
entity.setByteData( Byte.MAX_VALUE );
|
||||||
|
session.update( entity );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Testing maximal value.
|
||||||
|
scope.inTransaction(
|
||||||
|
session -> {
|
||||||
|
VariousTypesEntity entity = (VariousTypesEntity) session.createQuery(
|
||||||
|
" from VariousTypesEntity " +
|
||||||
|
" where byteData = java.lang.Byte.MAX_VALUE "
|
||||||
|
).uniqueResult();
|
||||||
|
assertNotNull( entity );
|
||||||
|
assertEquals( Byte.MAX_VALUE, entity.getByteData() );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
/*
|
||||||
|
* 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>.
|
||||||
|
*/
|
||||||
|
package org.hibernate.orm.test.typedescriptor;
|
||||||
|
|
||||||
|
|
||||||
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Strong Liu
|
||||||
|
*/
|
||||||
|
@DomainModel(
|
||||||
|
annotatedClasses = Issue.class
|
||||||
|
)
|
||||||
|
@SessionFactory
|
||||||
|
public class CharInNativeQueryTest {
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setUp(SessionFactoryScope scope) {
|
||||||
|
Issue issue = new Issue();
|
||||||
|
issue.setIssueNumber( "HHH-2304" );
|
||||||
|
issue.setDescription( "Wrong type detection for sql type char(x) columns" );
|
||||||
|
|
||||||
|
scope.inTransaction(
|
||||||
|
session ->
|
||||||
|
session.persist( issue )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void tearDown(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
session ->
|
||||||
|
session.createQuery( "delete from Issue" ).executeUpdate()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue(jiraKey = "HHH-2304")
|
||||||
|
public void testNativeQuery(SessionFactoryScope scope) {
|
||||||
|
|
||||||
|
|
||||||
|
Object issueNumber = scope.fromTransaction(
|
||||||
|
session ->
|
||||||
|
session.createNativeQuery( "select issue.issueNumber from Issue issue" ).uniqueResult()
|
||||||
|
);
|
||||||
|
|
||||||
|
assertNotNull( issueNumber );
|
||||||
|
assertTrue( issueNumber instanceof String );
|
||||||
|
assertEquals( "HHH-2304", issueNumber );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -4,7 +4,7 @@
|
||||||
* 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.test.typedescriptor;
|
package org.hibernate.orm.test.typedescriptor;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
|
@ -4,7 +4,7 @@
|
||||||
* 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.test.typedescriptor;
|
package org.hibernate.orm.test.typedescriptor;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
|
@ -1,82 +0,0 @@
|
||||||
/*
|
|
||||||
* 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>.
|
|
||||||
*/
|
|
||||||
package org.hibernate.test.typedescriptor;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.Transaction;
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
|
||||||
*/
|
|
||||||
public class ByteTest extends BaseCoreFunctionalTestCase {
|
|
||||||
public static final byte TEST_VALUE = 65;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
|
||||||
return new Class[] {
|
|
||||||
VariousTypesEntity.class
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@TestForIssue( jiraKey = "HHH-6533" )
|
|
||||||
public void testByteDataPersistenceAndRetrieval() {
|
|
||||||
Session session = openSession();
|
|
||||||
Transaction transaction = session.beginTransaction();
|
|
||||||
VariousTypesEntity entity = new VariousTypesEntity();
|
|
||||||
entity.setId( 1 );
|
|
||||||
entity.setByteData( TEST_VALUE );
|
|
||||||
session.persist( entity );
|
|
||||||
transaction.commit();
|
|
||||||
session.close();
|
|
||||||
|
|
||||||
// Testing sample value.
|
|
||||||
session = openSession();
|
|
||||||
transaction = session.beginTransaction();
|
|
||||||
entity = (VariousTypesEntity) session.createQuery(
|
|
||||||
" from VariousTypesEntity " +
|
|
||||||
" where byteData = org.hibernate.test.typedescriptor.ByteTest.TEST_VALUE "
|
|
||||||
).uniqueResult();
|
|
||||||
Assert.assertNotNull( entity );
|
|
||||||
Assert.assertEquals( TEST_VALUE, entity.getByteData() );
|
|
||||||
entity.setByteData( Byte.MIN_VALUE );
|
|
||||||
session.update( entity );
|
|
||||||
transaction.commit();
|
|
||||||
session.close();
|
|
||||||
|
|
||||||
// Testing minimal value.
|
|
||||||
session = openSession();
|
|
||||||
transaction = session.beginTransaction();
|
|
||||||
entity = (VariousTypesEntity) session.createQuery(
|
|
||||||
" from VariousTypesEntity " +
|
|
||||||
" where byteData = java.lang.Byte.MIN_VALUE "
|
|
||||||
).uniqueResult();
|
|
||||||
Assert.assertNotNull( entity );
|
|
||||||
Assert.assertEquals( Byte.MIN_VALUE, entity.getByteData() );
|
|
||||||
entity.setByteData( Byte.MAX_VALUE );
|
|
||||||
session.update( entity );
|
|
||||||
transaction.commit();
|
|
||||||
session.close();
|
|
||||||
|
|
||||||
// Testing maximal value.
|
|
||||||
session = openSession();
|
|
||||||
transaction = session.beginTransaction();
|
|
||||||
entity = (VariousTypesEntity) session.createQuery(
|
|
||||||
" from VariousTypesEntity " +
|
|
||||||
" where byteData = java.lang.Byte.MAX_VALUE "
|
|
||||||
).uniqueResult();
|
|
||||||
Assert.assertNotNull( entity );
|
|
||||||
Assert.assertEquals( Byte.MAX_VALUE, entity.getByteData() );
|
|
||||||
transaction.commit();
|
|
||||||
session.close();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,55 +0,0 @@
|
||||||
/*
|
|
||||||
* 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>.
|
|
||||||
*/
|
|
||||||
package org.hibernate.test.typedescriptor;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Strong Liu
|
|
||||||
*/
|
|
||||||
public class CharInNativeQueryTest extends BaseCoreFunctionalTestCase {
|
|
||||||
@Override
|
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
|
||||||
return new Class[] {
|
|
||||||
Issue.class
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
@TestForIssue(jiraKey = "HHH-2304")
|
|
||||||
public void testNativeQuery() {
|
|
||||||
Issue issue = new Issue();
|
|
||||||
issue.setIssueNumber( "HHH-2304" );
|
|
||||||
issue.setDescription( "Wrong type detection for sql type char(x) columns" );
|
|
||||||
|
|
||||||
Session session = openSession();
|
|
||||||
session.beginTransaction();
|
|
||||||
session.persist( issue );
|
|
||||||
session.getTransaction().commit();
|
|
||||||
session.close();
|
|
||||||
|
|
||||||
session = openSession( );
|
|
||||||
session.beginTransaction();
|
|
||||||
Object issueNumber = session.createNativeQuery( "select issue.issueNumber from Issue issue" ).uniqueResult();
|
|
||||||
session.getTransaction().commit();
|
|
||||||
session.close();
|
|
||||||
|
|
||||||
assertNotNull( issueNumber );
|
|
||||||
assertTrue( issueNumber instanceof String );
|
|
||||||
assertEquals( "HHH-2304", issueNumber );
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue