Skip to content

Commit

Permalink
HHH-10161 : Hibernate ignores return value from javax.persistence.Par…
Browse files Browse the repository at this point in the history
…ameter#getParameterType()

(cherry picked from commit b4dbb90)

Conflicts:
	hibernate-core/src/main/java/org/hibernate/internal/AbstractQueryImpl.java
	hibernate-core/src/test/java/org/hibernate/test/annotations/query/QueryAndSQLTest.java
	hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/QueryImpl.java
	hibernate-entitymanager/src/main/java/org/hibernate/jpa/spi/BaseQueryImpl.java
	hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/Item.java
	hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/query/QueryTest.java

HHH-10161 : Incorporate changes from conflicts
  • Loading branch information
gbadner committed Dec 7, 2015
1 parent 49e6230 commit 568b427
Show file tree
Hide file tree
Showing 5 changed files with 679 additions and 12 deletions.
Expand Up @@ -415,8 +415,12 @@ public Query setParameter(String name, Object val, Type type) {
}

public Query setParameter(int position, Object val) throws HibernateException {
if (val == null) {
setParameter( position, val, StandardBasicTypes.SERIALIZABLE );
if ( val == null ) {
Type type = parameterMetadata.getOrdinalParameterDescriptor( position + 1 ).getExpectedType();
if ( type == null ) {
type = StandardBasicTypes.SERIALIZABLE;
}
setParameter( position, val, type );
}
else {
setParameter( position, val, determineType( position, val ) );
Expand Down Expand Up @@ -483,7 +487,7 @@ private Type guessType(Object param) throws HibernateException {
return guessType( clazz );
}

private Type guessType(Class clazz) throws HibernateException {
public Type guessType(Class clazz) throws HibernateException {
String typename = clazz.getName();
Type type = session.getFactory().getTypeResolver().heuristicType(typename);
boolean serializable = type!=null && type instanceof SerializableType;
Expand Down
Expand Up @@ -37,17 +37,22 @@
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.dialect.Oracle8iDialect;
import org.hibernate.dialect.PostgreSQL81Dialect;
import org.hibernate.dialect.PostgreSQL82Dialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.dialect.PostgresPlusDialect;
import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.stat.Statistics;
import org.hibernate.test.annotations.A320;
import org.hibernate.test.annotations.A320b;
import org.hibernate.test.annotations.Plane;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.SkipForDialects;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.type.StandardBasicTypes;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand Down Expand Up @@ -106,6 +111,180 @@ public void testNativeQueryWithFormulaAttributeWithoutAlias() {
s.close();
}

@Test
@TestForIssue( jiraKey = "HHH-10161")
@SkipForDialects(
value = {
@SkipForDialect(value = Oracle8iDialect.class, jiraKey = "HHH-10161", comment = "Cannot convert untyped null (assumed to be BINARY type) to NUMBER"),
@SkipForDialect(value = PostgreSQL82Dialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint"),
@SkipForDialect(value = PostgresPlusDialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint")
}
)
public void testQueryWithNullParameter(){
Chaos c0 = new Chaos();
c0.setId( 0L );
c0.setName( "c0" );
c0.setSize( 0L );
Chaos c1 = new Chaos();
c1.setId( 1L );
c1.setName( "c1" );
c1.setSize( 1L );
Chaos c2 = new Chaos();
c2.setId( 2L );
c2.setName( "c2" );
c2.setSize( null );

Session s = openSession();
s.beginTransaction();
s.persist( c0 );
s.persist( c1 );
s.persist( c2 );

s.flush();
s.clear();

List chaoses = s.createQuery( "from Chaos where chaos_size is null or chaos_size = :chaos_size" )
.setParameter( "chaos_size", null )
.list();
assertEquals( 1, chaoses.size() );

chaoses = s.createQuery( "from Chaos where chaos_size = :chaos_size" )
.setParameter( "chaos_size", null )
.list();
// should be no results because null != null
assertEquals( 0, chaoses.size() );

s.getTransaction().rollback();
s.close();
}

@Test
@TestForIssue( jiraKey = "HHH-10161")
public void testQueryWithNullParameterTyped(){
Chaos c0 = new Chaos();
c0.setId( 0L );
c0.setName( "c0" );
c0.setSize( 0L );
Chaos c1 = new Chaos();
c1.setId( 1L );
c1.setName( "c1" );
c1.setSize( 1L );
Chaos c2 = new Chaos();
c2.setId( 2L );
c2.setName( "c2" );
c2.setSize( null );

Session s = openSession();
s.beginTransaction();
s.persist( c0 );
s.persist( c1 );
s.persist( c2 );

s.flush();
s.clear();

List chaoses = s.createQuery( "from Chaos where chaos_size is null or chaos_size = :chaos_size" )
.setParameter( "chaos_size", null, StandardBasicTypes.LONG )
.list();
assertEquals( 1, chaoses.size() );

chaoses = s.createQuery( "from Chaos where chaos_size = :chaos_size" )
.setParameter( "chaos_size", null, StandardBasicTypes.LONG )
.list();
// should be no results because null != null
assertEquals( 0, chaoses.size() );

s.getTransaction().rollback();
s.close();
}

@Test
@TestForIssue( jiraKey = "HHH-10161")
@SkipForDialects(
value = {
@SkipForDialect(value = Oracle8iDialect.class, jiraKey = "HHH-10161", comment = "Cannot convert untyped null (assumed to be BINARY type) to NUMBER"),
@SkipForDialect(value = PostgreSQL82Dialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint"),
@SkipForDialect(value = PostgresPlusDialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint")
}
)
public void testNativeQueryWithNullParameter(){
Chaos c0 = new Chaos();
c0.setId( 0L );
c0.setName( "c0" );
c0.setSize( 0L );
Chaos c1 = new Chaos();
c1.setId( 1L );
c1.setName( "c1" );
c1.setSize( 1L );
Chaos c2 = new Chaos();
c2.setId( 2L );
c2.setName( "c2" );
c2.setSize( null );

Session s = openSession();
s.beginTransaction();
s.persist( c0 );
s.persist( c1 );
s.persist( c2 );

s.flush();
s.clear();

List chaoses = s.createSQLQuery( "select * from Chaos where chaos_size is null or chaos_size = :chaos_size" )
.setParameter( "chaos_size", null )
.list();
assertEquals( 1, chaoses.size() );

chaoses = s.createSQLQuery( "select * from Chaos where chaos_size = :chaos_size" )
.setParameter( "chaos_size", null )
.list();
// should be no results because null != null
assertEquals( 0, chaoses.size() );

s.getTransaction().rollback();
s.close();
}

@Test
@TestForIssue( jiraKey = "HHH-10161")
public void testNativeQueryWithNullParameterTyped(){
Chaos c0 = new Chaos();
c0.setId( 0L );
c0.setName( "c0" );
c0.setSize( 0L );
Chaos c1 = new Chaos();
c1.setId( 1L );
c1.setName( "c1" );
c1.setSize( 1L );
Chaos c2 = new Chaos();
c2.setId( 2L );
c2.setName( "c2" );
c2.setSize( null );

Session s = openSession();
s.beginTransaction();
s.persist( c0 );
s.persist( c1 );
s.persist( c2 );

s.flush();
s.clear();

List chaoses = s.createSQLQuery( "select * from Chaos where chaos_size is null or chaos_size = :chaos_size" )
.setParameter( "chaos_size", null, StandardBasicTypes.LONG )
.list();
assertEquals( 1, chaoses.size() );

chaoses = s.createSQLQuery( "select * from Chaos where chaos_size = :chaos_size" )
.setParameter( "chaos_size", null, StandardBasicTypes.LONG )
.list();
// should be no results because null != null
assertEquals( 0, chaoses.size() );

s.getTransaction().rollback();
s.close();
}

@Test
public void testPackageQueries() throws Exception {
Session s = openSession();
Expand Down

0 comments on commit 568b427

Please sign in to comment.