Test for Issue HHH-12870
This commit is contained in:
parent
dc42deafcb
commit
7ee3b2858b
|
@ -935,9 +935,10 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
|
|||
if ( Tuple.class.equals( resultClass ) ) {
|
||||
query.setResultTransformer( new NativeQueryTupleTransformer() );
|
||||
}
|
||||
else {
|
||||
query.addEntity( "alias1", resultClass.getName(), LockMode.READ );
|
||||
}
|
||||
// why should we add here an Entity automatically: it's a wild guess and erratic most times
|
||||
// else {
|
||||
// query.addEntity( "alias1", resultClass.getName(), LockMode.READ );
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,31 +12,37 @@ package org.hibernate.test.sql.hand;
|
|||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class Speech {
|
||||
public class Speech implements SpeechInterface {
|
||||
private Integer id;
|
||||
private String name;
|
||||
private Double length;
|
||||
|
||||
@Override
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLength(Double length) {
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
//$Id: $
|
||||
package org.hibernate.test.sql.hand;
|
||||
|
||||
|
||||
/**
|
||||
* @author Günther Demetz
|
||||
*/
|
||||
public interface SpeechInterface {
|
||||
|
||||
public Integer getId();
|
||||
|
||||
public void setId(Integer id);
|
||||
|
||||
public Double getLength();
|
||||
|
||||
|
||||
public void setLength(Double length);
|
||||
|
||||
public String getName();
|
||||
|
||||
public void setName(String name);
|
||||
}
|
|
@ -31,6 +31,7 @@ import org.hibernate.dialect.H2Dialect;
|
|||
import org.hibernate.dialect.MySQL5Dialect;
|
||||
import org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn;
|
||||
import org.hibernate.engine.spi.NamedSQLQueryDefinitionBuilder;
|
||||
import org.hibernate.query.NativeQuery;
|
||||
import org.hibernate.transform.BasicTransformerAdapter;
|
||||
import org.hibernate.transform.DistinctRootEntityResultTransformer;
|
||||
import org.hibernate.transform.Transformers;
|
||||
|
@ -42,6 +43,7 @@ import org.hibernate.type.TimestampType;
|
|||
import org.hibernate.testing.FailureExpected;
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.test.sql.hand.Dimension;
|
||||
import org.hibernate.test.sql.hand.Employment;
|
||||
|
@ -53,6 +55,7 @@ import org.hibernate.test.sql.hand.Person;
|
|||
import org.hibernate.test.sql.hand.Product;
|
||||
import org.hibernate.test.sql.hand.SpaceShip;
|
||||
import org.hibernate.test.sql.hand.Speech;
|
||||
import org.hibernate.test.sql.hand.SpeechInterface;
|
||||
import org.hibernate.test.sql.hand.TextHolder;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -740,6 +743,48 @@ public class NativeSQLQueriesTest extends BaseCoreFunctionalTestCase {
|
|||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey="HHH-12870")
|
||||
public void testExplicitAddEntity() {
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
Speech speech = new Speech();
|
||||
speech.setLength( new Double( 23d ) );
|
||||
speech.setName( "Mine" );
|
||||
s.persist( speech );
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
NativeQuery<Speech> query = s.createNativeQuery( "select {s.*} from Speech s", Speech.class );
|
||||
query.addEntity("s", Speech.class);
|
||||
List<Speech> l = query.list();
|
||||
assertEquals( l.size(), 1 );
|
||||
|
||||
t.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey="HHH-12870")
|
||||
public void testInterfaceReturnType() {
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
Speech speech = new Speech();
|
||||
speech.setLength( new Double( 23d ) );
|
||||
speech.setName( "Mine" );
|
||||
s.persist( speech );
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
NativeQuery<SpeechInterface> query = s.createNativeQuery( "select {s.*} from Speech s", SpeechInterface.class );
|
||||
query.addEntity("s", Speech.class);
|
||||
List<SpeechInterface> l = query.list();
|
||||
assertEquals( l.size(), 1 );
|
||||
|
||||
t.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMixAndMatchEntityScalar() {
|
||||
|
|
Loading…
Reference in New Issue