-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-18864 - Creating NativeQuery with result-class leads to problems …
…with addEntity and addRoot
- Loading branch information
Showing
3 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
hibernate-core/src/test/java/org/hibernate/orm/test/sql/hand/SpeechInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
* Copyright Red Hat Inc. and Hibernate Authors | ||
*/ | ||
package org.hibernate.orm.test.sql.hand; | ||
|
||
/** | ||
* @author Steve Ebersole | ||
*/ | ||
public interface SpeechInterface { | ||
Integer getId(); | ||
void setId(Integer id); | ||
|
||
Double getLength(); | ||
void setLength(Double length); | ||
|
||
String getName(); | ||
void setName(String name); | ||
} |
131 changes: 131 additions & 0 deletions
131
...nate-core/src/test/java/org/hibernate/orm/test/sql/hand/query/EntityReturnClassTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
* Copyright Red Hat Inc. and Hibernate Authors | ||
*/ | ||
package org.hibernate.orm.test.sql.hand.query; | ||
|
||
import org.hibernate.orm.test.sql.hand.Speech; | ||
import org.hibernate.orm.test.sql.hand.SpeechInterface; | ||
import org.hibernate.query.NativeQuery; | ||
import org.hibernate.testing.orm.junit.DomainModel; | ||
import org.hibernate.testing.orm.junit.Jira; | ||
import org.hibernate.testing.orm.junit.JiraKey; | ||
import org.hibernate.testing.orm.junit.NotImplementedYet; | ||
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 java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* @author Steve Ebersole | ||
*/ | ||
@SuppressWarnings("JUnitMalformedDeclaration") | ||
@DomainModel(annotatedClasses = {SpeechInterface.class, Speech.class}) | ||
@SessionFactory | ||
@Jira("https://hibernate.atlassian.net/browse/HHH-18864") | ||
public class EntityReturnClassTests { | ||
|
||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
// no return-class -> no problem | ||
|
||
@Test | ||
@JiraKey("HHH-18864") | ||
public void testAddEntityNoReturn(SessionFactoryScope scope) { | ||
scope.inTransaction( (session) -> { | ||
//noinspection unchecked,deprecation | ||
NativeQuery<Speech> query = session.createNativeQuery( "select {s.*} from Speech s" ); | ||
query.addEntity("s", Speech.class); | ||
List<Speech> l = query.list(); | ||
assertEquals( l.size(), 1 ); | ||
} ); | ||
} | ||
|
||
@Test | ||
@JiraKey("HHH-18864") | ||
public void testAddRootNoReturn(SessionFactoryScope scope) { | ||
scope.inTransaction( (session) -> { | ||
//noinspection unchecked,deprecation | ||
NativeQuery<Speech> query = session.createNativeQuery( "select {s.*} from Speech s" ); | ||
query.addRoot("s", Speech.class); | ||
List<Speech> l = query.list(); | ||
assertEquals( l.size(), 1 ); | ||
} ); | ||
} | ||
|
||
|
||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
// entity return-class -> problems with 2 `ResultBuilder` refs | ||
|
||
@Test | ||
@JiraKey("HHH-18864") | ||
@NotImplementedYet | ||
public void testAddEntityWithEntityReturn(SessionFactoryScope scope) { | ||
scope.inTransaction( (session) -> { | ||
NativeQuery<Speech> query = session.createNativeQuery( "select {s.*} from Speech s", Speech.class ); | ||
query.addEntity("s", Speech.class); | ||
List<Speech> l = query.list(); | ||
assertEquals( l.size(), 1 ); | ||
} ); | ||
} | ||
|
||
@Test | ||
@JiraKey("HHH-18864") | ||
@NotImplementedYet | ||
public void testAddRootWithEntityReturn(SessionFactoryScope scope) { | ||
scope.inTransaction( (session) -> { | ||
NativeQuery<Speech> query = session.createNativeQuery( "select {s.*} from Speech s", Speech.class ); | ||
query.addRoot("s", Speech.class); | ||
List<Speech> l = query.list(); | ||
assertEquals( l.size(), 1 ); | ||
} ); | ||
} | ||
|
||
|
||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
// entity-interface return-class -> problems with `JdbcType` determination | ||
|
||
@Test | ||
@JiraKey("HHH-18864") | ||
@NotImplementedYet | ||
public void testAddEntityWithInterfaceReturn(SessionFactoryScope scope) { | ||
scope.inTransaction( (session) -> { | ||
NativeQuery<SpeechInterface> query = session.createNativeQuery( "select {s.*} from Speech s", SpeechInterface.class ); | ||
query.addEntity("s", Speech.class); | ||
List<SpeechInterface> l = query.list(); | ||
assertEquals( l.size(), 1 ); | ||
} ); | ||
} | ||
|
||
@Test | ||
@JiraKey("HHH-18864") | ||
@NotImplementedYet | ||
public void testAddRootWithInterfaceReturn(SessionFactoryScope scope) { | ||
scope.inTransaction( (session) -> { | ||
NativeQuery<SpeechInterface> query = session.createNativeQuery( "select {s.*} from Speech s", SpeechInterface.class ); | ||
query.addRoot("s", Speech.class); | ||
List<SpeechInterface> l = query.list(); | ||
assertEquals( l.size(), 1 ); | ||
} ); | ||
} | ||
|
||
|
||
@BeforeEach | ||
void prepareTestData(SessionFactoryScope scope) { | ||
scope.inTransaction( (session) -> { | ||
Speech speech = new Speech(); | ||
speech.setLength( 23d ); | ||
speech.setName( "Mine" ); | ||
session.persist( speech ); | ||
} ); | ||
} | ||
|
||
@AfterEach | ||
void dropTestData(SessionFactoryScope scope) { | ||
scope.inTransaction( (session) -> session.createMutationQuery( "delete Speech" ).executeUpdate() ); | ||
} | ||
} |