question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Qute template problem (reactive)

See original GitHub issue

Describe the bug

@Path("/test")
@ApplicationScoped
public class IndexTestController {

	@GET
	public Uni<Object> wei(@QueryParam("page") Integer page) {
		page = page != null ? page : 1;
		Integer page2 = page;
		return Panache.getSession().flatMap(session -> session.withTransaction(tran -> {
			Uni<List<Object>> singleResult = session.createNativeQuery("select types from Posts").getResultList();
			PanacheQuery<Posts> panacheQuery = Posts.findAll(Sort.by("createDate", Direction.Descending))
					.page(page2 - 1, 10);
			Uni<Long> count = panacheQuery.count();
			Uni<List<Posts>> list = panacheQuery.list();
			Uni<List<Posts>> rightReads = Posts.findAll(Sort.by("readNum", Direction.Descending)).page(page2 - 1, 10)
					.list();
			return Uni.combine().all().unis(count, list, rightReads, singleResult)
					.combinedWith((c, l, reads, types) -> {
						PageView<Posts> pageView = new PageView<Posts>(10, page2);
						QueryResult<Posts> queryResult = new QueryResult<Posts>();
						queryResult.setTotalRecord(c);
						queryResult.setResultList(l);
						pageView.setQueryResult(queryResult);

						IndexVo indexVo = new IndexVo();
						indexVo.pageView = pageView;
						indexVo.rightNews = queryResult.getResultList();
						indexVo.rightReads = reads;
						List<String> split = BaseUtil.listSplit(types);
						Map<String, Long> map = split.stream()
								.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
						indexVo.mapType = sortByValue(map);
						return indexVo;
					});
		}));
	}

This code is ok。 but:

       @GET
	public TemplateInstance wei(@QueryParam("page") Integer page) {
		page = page != null ? page : 1;
		Integer page2 = page;
		
		Uni<IndexVo> indexVos = Panache.getSession().flatMap(session->session.withTransaction(tran->{
			Uni<List<Object>> singleResult = session.createNativeQuery("select types from Posts").getResultList();
			PanacheQuery<Posts> panacheQuery = Posts.findAll(Sort.by("createDate", Direction.Descending)).page(page2 - 1,
					10);
			Uni<Long> count = panacheQuery.count();
			Uni<List<Posts>> list = panacheQuery.list();
			Uni<List<Posts>> rightReads = Posts.findAll(Sort.by("readNum", Direction.Descending)).page(page2 - 1, 10)
					.list();
			return Uni.combine().all().unis(count, list, rightReads,singleResult).combinedWith((c, l, reads,types) -> {
				PageView<Posts> pageView = new PageView<Posts>(10, page2);
				QueryResult<Posts> queryResult = new QueryResult<Posts>();
				queryResult.setTotalRecord(c);
				queryResult.setResultList(l);
				pageView.setQueryResult(queryResult);

				IndexVo indexVo = new IndexVo();
				indexVo.pageView = pageView;
				indexVo.rightNews = queryResult.getResultList();
				indexVo.rightReads = reads;
				List<String> split = BaseUtil.listSplit(types);
				Map<String, Long> map = split.stream()
						.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
				indexVo.mapType = sortByValue(map);
				return indexVo;
			});
		}));

		return index.data("indexVo", indexVos);
	}

This code is error:

2022-10-25 15:53:28,944 ERROR [org.hib.rea.errors] (vert.x-eventloop-thread-1) HR000057: Failed to execute statement [select count(*) as col_0_0_ from Posts posts0_]: could not execute query: java.util.concurrent.CompletionException: java.lang.IllegalStateException: HR000061: Session is currently connecting to database
	at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:332)
	at java.base/java.util.concurrent.CompletableFuture.uniComposeStage(CompletableFuture.java:1177)
	at java.base/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:2309)
	at java.base/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:144)
	at org.hibernate.reactive.loader.ReactiveLoader.doReactiveQueryAndInitializeNonLazyCollections(ReactiveLoader.java:75)
	at org.hibernate.reactive.loader.CachingReactiveLoader.doReactiveList(CachingReactiveLoader.java:62)
	at org.hibernate.reactive.loader.CachingReactiveLoader.reactiveListIgnoreQueryCache(CachingReactiveLoader.java:80)
	at org.hibernate.reactive.loader.hql.impl.ReactiveQueryLoader.reactiveList(ReactiveQueryLoader.java:129)
	at org.hibernate.reactive.loader.hql.impl.ReactiveQueryLoader.reactiveList(ReactiveQueryLoader.java:95)
	at org.hibernate.reactive.session.impl.ReactiveQueryTranslatorImpl.reactiveList(ReactiveQueryTranslatorImpl.java:132)
	at org.hibernate.reactive.session.impl.ReactiveHQLQueryPlan.performReactiveList(ReactiveHQLQueryPlan.java:114)
	at org.hibernate.reactive.session.impl.ReactiveSessionImpl.lambda$reactiveList$9(ReactiveSessionImpl.java:461)
	at java.base/java.util.concurrent.CompletableFuture.uniComposeStage(CompletableFuture.java:1187)
	at java.base/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:2309)
	at java.base/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:144)
	at org.hibernate.reactive.session.impl.ReactiveSessionImpl.reactiveList(ReactiveSessionImpl.java:461)
	at org.hibernate.reactive.session.impl.ReactiveQueryImpl.doReactiveList(ReactiveQueryImpl.java:151)
	at org.hibernate.reactive.session.impl.ReactiveQueryImpl.getReactiveResultList(ReactiveQueryImpl.java:127)
	at org.hibernate.reactive.session.impl.ReactiveQueryImpl.getReactiveSingleResult(ReactiveQueryImpl.java:94)
	at io.smallrye.context.impl.wrappers.SlowContextualSupplier.get(SlowContextualSupplier.java:21)
	at io.smallrye.mutiny.operators.uni.builders.UniCreateFromCompletionStage.subscribe(UniCreateFromCompletionStage.java:24)
	at io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:36)
	at io.smallrye.mutiny.operators.uni.UniRunSubscribeOn.lambda$subscribe$0(UniRunSubscribeOn.java:27)
	at org.hibernate.reactive.context.impl.VertxContext.execute(VertxContext.java:90)
	at io.smallrye.mutiny.operators.uni.UniRunSubscribeOn.subscribe(UniRunSubscribeOn.java:25)
	at io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:36)
	at io.smallrye.mutiny.operators.uni.UniOnItemTransformToUni$UniOnItemTransformToUniProcessor.performInnerSubscription(UniOnItemTransformToUni.java:81)
	at io.smallrye.mutiny.operators.uni.UniOnItemTransformToUni$UniOnItemTransformToUniProcessor.onItem(UniOnItemTransformToUni.java:57)
	at io.smallrye.mutiny.operators.uni.builders.UniCreateFromKnownItem$KnownItemSubscription.forward(UniCreateFromKnownItem.java:38)
	at io.smallrye.mutiny.operators.uni.builders.UniCreateFromKnownItem$KnownItemSubscription.access$100(UniCreateFromKnownItem.java:26)
	at io.smallrye.mutiny.operators.uni.builders.UniCreateFromKnownItem.subscribe(UniCreateFromKnownItem.java:23)
	at io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:36)
	at io.smallrye.mutiny.operators.uni.UniOnItemTransformToUni.subscribe(UniOnItemTransformToUni.java:25)
	at io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:36)
	at io.smallrye.mutiny.operators.uni.UniAndCombination$UniHandler.subscribe(UniAndCombination.java:234)
	at io.smallrye.mutiny.operators.uni.UniAndCombination$AndSupervisor.run(UniAndCombination.java:88)
	at io.smallrye.mutiny.operators.uni.UniAndCombination$AndSupervisor.access$000(UniAndCombination.java:57)
	at io.smallrye.mutiny.operators.uni.UniAndCombination.subscribe(UniAndCombination.java:54)
	at io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:36)
	at io.smallrye.mutiny.operators.uni.UniOnItemTransformToUni$UniOnItemTransformToUniProcessor.performInnerSubscription(UniOnItemTransformToUni.java:81)
	at io.smallrye.mutiny.operators.uni.UniOnItemTransformToUni$UniOnItemTransformToUniProcessor.onItem(UniOnItemTransformToUni.java:57)
	at io.smallrye.mutiny.operators.uni.builders.UniCreateFromKnownItem$KnownItemSubscription.forward(UniCreateFromKnownItem.java:38)
	at io.smallrye.mutiny.operators.uni.builders.UniCreateFromKnownItem$KnownItemSubscription.access$100(UniCreateFromKnownItem.java:26)
	at io.smallrye.mutiny.operators.uni.builders.UniCreateFromKnownItem.subscribe(UniCreateFromKnownItem.java:23)
	at io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:36)
	at io.smallrye.mutiny.operators.uni.UniOnItemTransformToUni.subscribe(UniOnItemTransformToUni.java:25)
	at io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:36)
	at io.smallrye.mutiny.groups.UniSubscribe.withSubscriber(UniSubscribe.java:52)
	at io.smallrye.mutiny.groups.UniSubscribe.with(UniSubscribe.java:112)
	at io.smallrye.mutiny.operators.uni.UniSubscribeToCompletionStage.subscribe(UniSubscribeToCompletionStage.java:30)
	at io.smallrye.mutiny.groups.UniSubscribe.asCompletionStage(UniSubscribe.java:178)
	at io.smallrye.mutiny.groups.UniSubscribe.asCompletionStage(UniSubscribe.java:165)
	at io.smallrye.mutiny.Uni.subscribeAsCompletionStage(Uni.java:142)
	at io.quarkus.qute.EvaluatorImpl.toCompletionStage(EvaluatorImpl.java:228)
	at io.quarkus.qute.EvaluatorImpl.lambda$resolve$4(EvaluatorImpl.java:216)
	at io.quarkus.qute.CompletedStage.thenCompose(CompletedStage.java:232)
	at io.quarkus.qute.EvaluatorImpl.resolve(EvaluatorImpl.java:209)
	at io.quarkus.qute.EvaluatorImpl.resolveReference(EvaluatorImpl.java:132)
	at io.quarkus.qute.EvaluatorImpl.evaluate(EvaluatorImpl.java:90)
	at io.quarkus.qute.ResolutionContextImpl.evaluate(ResolutionContextImpl.java:29)
	at io.quarkus.qute.LoopSectionHelper.resolve(LoopSectionHelper.java:45)
	at io.quarkus.qute.SectionNode.resolve(SectionNode.java:50)
	at io.quarkus.qute.SectionNode$SectionResolutionContextImpl.execute(SectionNode.java:184)
	at io.quarkus.qute.SectionHelper$SectionResolutionContext.execute(SectionHelper.java:46)
	at io.quarkus.qute.Parser$1.resolve(Parser.java:1233)
	at io.quarkus.qute.SectionNode.resolve(SectionNode.java:50)
	at io.quarkus.qute.TemplateImpl$TemplateInstanceImpl.renderData(TemplateImpl.java:178)
	at io.quarkus.qute.TemplateImpl$TemplateInstanceImpl.renderAsyncNoTimeout(TemplateImpl.java:169)
	at io.smallrye.context.impl.wrappers.SlowContextualSupplier.get(SlowContextualSupplier.java:21)
	at io.smallrye.mutiny.operators.uni.builders.UniCreateFromCompletionStage.subscribe(UniCreateFromCompletionStage.java:24)
	at io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:36)
	at io.smallrye.mutiny.operators.uni.UniFailOnTimeout.subscribe(UniFailOnTimeout.java:36)
	at io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:36)
	at io.smallrye.mutiny.groups.UniSubscribe.withSubscriber(UniSubscribe.java:52)
	at io.smallrye.mutiny.groups.UniSubscribe.with(UniSubscribe.java:112)
	at io.smallrye.mutiny.groups.UniSubscribe.with(UniSubscribe.java:89)
	at org.jboss.resteasy.reactive.server.handlers.UniResponseHandler.handle(UniResponseHandler.java:19)
	at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:124)
	at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:142)
	at org.jboss.resteasy.reactive.server.handlers.RestInitialHandler.beginProcessing(RestInitialHandler.java:51)
	at org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveVertxHandler.handle(ResteasyReactiveVertxHandler.java:18)
	at org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveVertxHandler.handle(ResteasyReactiveVertxHandler.java:8)
	at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1284)
	at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:173)
	at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:140)
	at io.quarkus.vertx.http.runtime.StaticResourcesRecorder$2.handle(StaticResourcesRecorder.java:84)
	at io.quarkus.vertx.http.runtime.StaticResourcesRecorder$2.handle(StaticResourcesRecorder.java:71)
	at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1284)
	at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:136)
	at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:140)
	at io.vertx.ext.web.handler.impl.StaticHandlerImpl.lambda$sendStatic$1(StaticHandlerImpl.java:290)
	at io.vertx.core.impl.future.FutureImpl$3.onSuccess(FutureImpl.java:141)
	at io.vertx.core.impl.future.FutureBase.lambda$emitSuccess$0(FutureBase.java:54)
	at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.IllegalStateException: HR000061: Session is currently connecting to database
	at org.hibernate.reactive.pool.impl.ProxyConnection.withConnection(ProxyConnection.java:66)
	at org.hibernate.reactive.pool.impl.ProxyConnection.selectJdbc(ProxyConnection.java:129)
	at org.hibernate.reactive.pool.BatchingConnection.selectJdbc(BatchingConnection.java:173)
	at org.hibernate.reactive.loader.ReactiveLoader.executeReactiveQueryStatement(ReactiveLoader.java:128)
	at org.hibernate.reactive.loader.ReactiveLoader.doReactiveQueryAndInitializeNonLazyCollections(ReactiveLoader.java:69)
	... 96 more

Differences between the two pieces of code: return Uni<Object> or TemplateInstance(qute)

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

jdk17

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.13.3

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:19 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
weir2010commented, Oct 26, 2022

yes! return index.data(“indexVo”, indexVos.memoize().indefinitely()) is ok!

0reactions
DavideDcommented, Oct 26, 2022

I’ve just tested locally and it seems to work

Read more comments on GitHub >

github_iconTop Results From Across the Web

Qute Templating Engine - Quarkus
Qute is a templating engine designed specifically to meet the Quarkus needs. The usage of reflection is minimized to reduce the size of...
Read more >
Can't use Qute in reactive application · Issue #14550 - GitHub
When trying to build an application using RestEasy Reactive and Qute for rendering responses from templates, this exception is raised:.
Read more >
Qute Templating Engine
Qute is a templating engine designed specifically to meet the Quarkus needs. The usage of reflection is minimized to reduce the size of...
Read more >
Quarkus Qute – A Test Ride - Gunnar Morling
A very nice aspect about Qute templates is that they are processed at ... This means if there is an error in a...
Read more >
Template Parameter Declarations - Kube by Example
Qute checks the syntax and will fail the build (and result in a prettified HTML error screen if accessed through a browser) when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found