Skip to content

Commit

Permalink
Fix native query support in Hibernate Reactive
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand authored and sberyozkin committed Jun 21, 2023
1 parent d1a5a87 commit 7f57ea1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import io.quarkus.deployment.builditem.SystemPropertyBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
import io.quarkus.deployment.recording.RecorderContext;
import io.quarkus.hibernate.orm.deployment.HibernateConfigUtil;
Expand Down Expand Up @@ -101,6 +102,13 @@ void reflections(BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, REFLECTIVE_CONSTRUCTORS_NEEDED));
}

@BuildStep
void services(BuildProducer<ServiceProviderBuildItem> producer) {
producer.produce(
new ServiceProviderBuildItem(org.hibernate.service.spi.SessionFactoryServiceContributor.class.getName(),
org.hibernate.reactive.service.internal.ReactiveSessionFactoryServiceContributor.class.getName()));
}

@BuildStep
@Record(STATIC_INIT)
public void build(RecorderContext recorderContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.NamedNativeQuery;
import jakarta.persistence.Table;

@Entity
@Table(name = "Pig")
@NamedNativeQuery(name = "pig.all", query = "select * from Pig", resultClass = GuineaPig.class)
public class GuineaPig {

@Id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.quarkus.it.hibernate.reactive.postgresql;

import java.util.List;

import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
Expand All @@ -25,6 +27,13 @@ public class HibernateReactiveTestEndpoint {
@Inject
PgPool pgPool;

@GET
@Path("/reactiveFindNativeQuery")
public Uni<List<GuineaPig>> reactiveFindNativeQuery() {
return populateDB()
.chain(() -> sessionFactory.withSession(s -> s.createNamedQuery("pig.all", GuineaPig.class).getResultList()));
}

@GET
@Path("/reactiveFindMutiny")
public Uni<GuineaPig> reactiveFindMutiny() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.it.hibernate.reactive.postgresql;

import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;

Expand All @@ -18,6 +19,15 @@
@TestHTTPEndpoint(HibernateReactiveTestEndpoint.class)
public class HibernateReactiveTest {

@Test
public void reactiveFindNativeQuery() {
RestAssured.given().when()
.auth().preemptive().basic("scott", "jb0ss")
.get("/reactiveFindNativeQuery")
.then()
.statusCode(anyOf(is(200), is(204)));
}

@Test
public void reactiveCowPersist() {
RestAssured.given().when()
Expand Down

0 comments on commit 7f57ea1

Please sign in to comment.