当前位置: 首页 > 知识库问答 >
问题:

如何用Quarkus Panache在select查询中使用LocalTime

长孙硕
2023-03-14

我尝试为特定的LocalDateTime查找我的实体OpeningTimes。我的实体知道一周中的几天作为集合,知道两个localtime作为开始和结束。

我的实体是这样的:

package org.something.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
import io.quarkus.runtime.annotations.RegisterForReflection;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.validation.constraints.NotNull;
import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.*;

import static org.hibernate.annotations.CascadeType.ALL;

@Entity
@JsonIgnoreProperties(
    value = {"persistent"},
    ignoreUnknown = true)
@RegisterForReflection
public class OpeningTimes extends PanacheEntityBase {
  private static final String FIND_OPENINGS_BY_DATETIME_QUERY =
      "SELECT DISTINCT openings FROM OpeningTimes openings WHERE ?1 IN daysOfWeek AND timeFrom <= ?2 AND timeTo >= ?2";

  @Id
  @GeneratedValue(generator = "UUID")
  @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
  private UUID id;

  @NotNull private String name;
  private String description;
  private LocalTime timeFrom;
  private LocalTime timeTo;

  @ElementCollection
  @Cascade(value = {ALL})
  private Collection<DayOfWeek> daysOfWeek;

  /** DO NOT USE! ONLY FOR JPA! */
  public OpeningTimes() {
    super();
    name = "";
  }

  @JsonCreator
  public OpeningTimes(
      @JsonProperty("name") String name,
      @JsonProperty("timeFrom") LocalTime timeFrom,
      @JsonProperty("timeTo") LocalTime timeTo,
      @JsonProperty("daysOfWeek") Collection<DayOfWeek> daysOfWeek) {
    this.name = name;
    this.timeFrom = timeFrom;
    this.timeTo = timeTo;
    this.daysOfWeek = new HashSet<>(daysOfWeek);
  }

  public OpeningTimes(String name, LocalTime from, LocalTime to, DayOfWeek... daysOfWeek) {
    this(name, from, to, new ArrayList<>(Arrays.asList(daysOfWeek)));
  }

  public static List<OpeningTimes> findByDateTime(LocalDateTime dateTime) {
    return find(FIND_OPENINGS_BY_DATETIME_QUERY, dateTime.getDayOfWeek(), dateTime.toLocalTime())
        .list();
  }

  public LocalTime getTimeFrom() {
    return timeFrom;
  }

  public void setTimeFrom(LocalTime timeFrom) {
    this.timeFrom = timeFrom;
  }

  public LocalTime getTimeTo() {
    return timeTo;
  }

  public void setTimeTo(LocalTime timeTo) {
    this.timeTo = timeTo;
  }

  public Collection<DayOfWeek> getDaysOfWeek() {
    return daysOfWeek;
  }

  public void setDaysOfWeek(Set<DayOfWeek> daysOfWeek) {
    this.daysOfWeek = daysOfWeek;
  }

  public UUID getId() {
    return id;
  }

  public void setId(UUID id) {
    this.id = id;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getDescription() {
    return description;
  }

  public void setDescription(String description) {
    this.description = description;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (!(o instanceof OpeningTimes)) return false;
    OpeningTimes that = (OpeningTimes) o;
    return Objects.equals(getId(), that.getId())
        && Objects.equals(getName(), that.getName())
        && Objects.equals(getDescription(), that.getDescription())
        && Objects.equals(getTimeFrom(), that.getTimeFrom())
        && Objects.equals(getTimeTo(), that.getTimeTo())
        && Objects.equals(getDaysOfWeek(), that.getDaysOfWeek());
  }

  @Override
  public int hashCode() {
    return Objects.hash(
        getId(), getName(), getDescription(), getTimeFrom(), getTimeTo(), getDaysOfWeek());
  }

  @Override
  public String toString() {
    return "OpeningTimes{"
        + "id="
        + id
        + ", name='"
        + name
        + '\''
        + ", description='"
        + description
        + '\''
        + ", timeFrom="
        + timeFrom
        + ", timeTo="
        + timeTo
        + ", daysOfWeek="
        + daysOfWeek
        + '}';
  }

  public void merge(OpeningTimes openingTimes) {
    this.name = openingTimes.name;
    this.description = openingTimes.description;
    this.timeFrom = openingTimes.timeFrom;
    this.timeTo = openingTimes.timeTo;
    this.daysOfWeek = openingTimes.daysOfWeek;
  }
}

当我运行调用FindByDateTime方法的测试时,我得到以下信息:

Apr 10, 2020 2:02:11 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 0, SQLState: 42601
Apr 10, 2020 2:02:11 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: ERROR: syntax error at or near "{"
  Position: 332


javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet

    at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154)
    at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1539)
    at org.hibernate.query.Query.getResultList(Query.java:165)
    at io.quarkus.hibernate.orm.panache.runtime.PanacheQueryImpl.list(PanacheQueryImpl.java:137)
    at eu.wiegandt.openworkshoporganizer.model.OpeningTimes.findByDateTime(OpeningTimes.java:70)
    at eu.wiegandt.openworkshoporganizer.OpeningTimesIT.findByDateTime_InRange_TestEvent(OpeningTimesIT.java:38)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at io.quarkus.test.junit.QuarkusTestExtension.runExtensionMethod(QuarkusTestExtension.java:342)
    at io.quarkus.test.junit.QuarkusTestExtension.interceptTestMethod(QuarkusTestExtension.java:281)
    at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
    at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
    at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)
    at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)
    at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:205)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:201)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:137)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:71)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:248)
    at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$5(DefaultLauncher.java:211)
    at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:226)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:199)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:132)
    at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
    Suppressed: java.lang.IllegalArgumentException: Removing a detached instance eu.wiegandt.openworkshoporganizer.model.OpeningTimes#f30bcdfe-c67c-441b-af5d-255a6f5ce871
        at org.hibernate.event.internal.DefaultDeleteEventListener.disallowDeletionOfDetached(DefaultDeleteEventListener.java:190)
        at org.hibernate.event.internal.DefaultDeleteEventListener.performDetachedEntityDeletionCheck(DefaultDeleteEventListener.java:178)
        at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:105)
        at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:72)
        at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:102)
        at org.hibernate.internal.SessionImpl.fireDelete(SessionImpl.java:894)
        at org.hibernate.internal.SessionImpl.delete(SessionImpl.java:826)
        at org.hibernate.internal.SessionImpl.remove(SessionImpl.java:3261)
        at io.quarkus.hibernate.orm.runtime.entitymanager.TransactionScopedEntityManager.remove(TransactionScopedEntityManager.java:134)
        at io.quarkus.hibernate.orm.runtime.entitymanager.ForwardingEntityManager.remove(ForwardingEntityManager.java:37)
        at io.quarkus.hibernate.orm.panache.runtime.JpaOperations.delete(JpaOperations.java:60)
        at io.quarkus.hibernate.orm.panache.PanacheEntityBase.delete(PanacheEntityBase.java:70)
        at eu.wiegandt.openworkshoporganizer.OpeningTimesIT.cleanUpDatabase(OpeningTimesIT.java:49)
        at eu.wiegandt.openworkshoporganizer.OpeningTimesIT_Subclass.cleanUpDatabase$$superaccessor6(OpeningTimesIT_Subclass.zig:332)
        at eu.wiegandt.openworkshoporganizer.OpeningTimesIT_Subclass$$function$$6.apply(OpeningTimesIT_Subclass$$function$$6.zig:47)
        at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
        at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorBase.invokeInOurTx(TransactionalInterceptorBase.java:119)
        at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorBase.invokeInOurTx(TransactionalInterceptorBase.java:92)
        at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorRequired.doIntercept(TransactionalInterceptorRequired.java:32)
        at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorBase.intercept(TransactionalInterceptorBase.java:53)
        at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorRequired.intercept(TransactionalInterceptorRequired.java:26)
        at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorRequired_Bean.intercept(TransactionalInterceptorRequired_Bean.zig:168)
        at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
        at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
        at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
        at eu.wiegandt.openworkshoporganizer.OpeningTimesIT_Subclass.cleanUpDatabase(OpeningTimesIT_Subclass.zig:276)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at io.quarkus.test.junit.QuarkusTestExtension.runExtensionMethod(QuarkusTestExtension.java:342)
        at io.quarkus.test.junit.QuarkusTestExtension.interceptAfterEachMethod(QuarkusTestExtension.java:303)
        at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
        at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
        at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
        at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
        at org.junit.jupiter.engine.extension.TimeoutExtension.interceptLifecycleMethod(TimeoutExtension.java:126)
        at org.junit.jupiter.engine.extension.TimeoutExtension.interceptAfterEachMethod(TimeoutExtension.java:108)
        at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
        at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
        at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
        at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
        at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
        at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
        at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
        at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
        at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeMethodInExtensionContext(ClassBasedTestDescriptor.java:481)
        at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$synthesizeAfterEachMethodAdapter$19(ClassBasedTestDescriptor.java:471)
        at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeAfterEachMethods$9(TestMethodTestDescriptor.java:231)
        at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeAllAfterMethodsOrCallbacks$13(TestMethodTestDescriptor.java:268)
        at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
        at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeAllAfterMethodsOrCallbacks$14(TestMethodTestDescriptor.java:268)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
        at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeAllAfterMethodsOrCallbacks(TestMethodTestDescriptor.java:267)
        at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeAfterEachMethods(TestMethodTestDescriptor.java:229)
        at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:141)
        ... 41 more
Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
    at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:103)
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:67)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:2292)
    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2050)
    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2012)
    at org.hibernate.loader.Loader.doQuery(Loader.java:953)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354)
    at org.hibernate.loader.Loader.doList(Loader.java:2838)
    at org.hibernate.loader.Loader.doList(Loader.java:2820)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2652)
    at org.hibernate.loader.Loader.list(Loader.java:2647)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:506)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:396)
    at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:219)
    at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1404)
    at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1562)
    at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1530)
    ... 69 more
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "{"
  Position: 332
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2578)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2313)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:331)
    at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:448)
    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:369)
    at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:159)
    at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:109)
    at io.agroal.pool.wrapper.PreparedStatementWrapper.executeQuery(PreparedStatementWrapper.java:75)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:57)
    ... 84 more


Apr 10, 2020 2:02:11 PM io.quarkus.runtime.Timing printStopTime
INFO: Quarkus stopped in 0.031s

我搜索了一些关于如何在localdatetime中正确使用panache的信息,但不幸的是,我没有找到任何信息。

共有1个答案

丰景同
2023-03-14

我可以通过调试和查找hibernate创建的查询来找到错误。我找到了以下查询:

select distinct openingtim0_.id as id1_1_, openingtim0_.description as descript2_1_, openingtim0_.name as name3_1_, openingtim0_.timeFrom as timefrom4_1_, openingtim0_.timeTo as timeto5_1_ from OpeningTimes openingtim0_ cross join OpeningTimes_daysOfWeek daysofweek1_ where openingtim0_.id=daysofweek1_.OpeningTimes_id and (? in ({non-qualified-property-ref})) and (? between openingtim0_.timeFrom and openingtim0_.timeTo)

这时我的疑问是:

SELECT DISTINCT openings FROM OpeningTimes openings WHERE ?1 IN daysOfWeek AND ?2 BETWEEN timeFrom AND timeTo

因此,错误不是与localtime有关,而是与天数集合有关。

SELECT DISTINCT openings FROM OpeningTimes openings WHERE ?1 IN elements(openings.daysOfWeek) AND ?2 BETWEEN timeFrom AND timeTo
 类似资料:
  • 问题内容: 我有5个表或表要从\查询 我的语法我喜欢这样 问题是,当我运行此命令时,我收到一条错误消息:“ .....您在SQL WHERE Patient_ID =吗?附近有错误?” 当我使用system.out.println(sql2)输出sql时; 值未在sql2中设置 问题答案: 当您准备一条语句时,数据库将构造一个执行计划,如果表不存在,则该计划无法执行。换句话说,Placehodle

  • 来自Teradata,我通常会创建一个包含一些变量的易失性表,我会在代码中使用这些变量。 例如。, 然后我会在SELECT WHERE子句中使用该表: 我试图在色调(Impala editor)中执行类似的操作,但遇到了一个错误: AnalysisException:第5行中的语法错误:未定义:来自表名隐藏^遇到:来自预期的:大小写、强制转换、默认值、存在、FALSE、IF、INTERVAL、NO

  • 问题内容: 我正在尝试在MySQL选择查询中使用一条语句。 我在第一个语句之后出现错误。 为什么这不起作用?在MySQL查询中执行IF语句的正确方法是什么? 问题答案: 您使用的IF / THEN / ELSE构造仅在存储过程和函数中有效。您的查询将需要重组,因为您不能使用IF()函数来控制WHERE子句的流程。 可以在查询中使用的IF()函数主要用于在查询的SELECT部分​​中根据某些条件选择

  • 问题内容: 我有此表变量声明后跟一个查询: 并定义如下: 当我在SQL Management Studio中针对SQL Server 2005 Express运行它时,得到以下信息: 消息208,第16级,状态1,第24行 无效的对象名称“ @CurrentItems”。 实际的问题是什么,我该如何解决? 问题答案: 您已经别名了,所以只需使用: 还要看看您的查询中是否有类似的内容。什么是CU?您

  • 问题内容: 我正在使用Firebase函数和Firebase Firestore开发用于存储用户数据的API。 我想使用存储在其字段中的属性来查找文档。这是Firebase文档,其中说明了如何实现相同的功能。 我想处理两种情况 在没有文件的情况下 有两个以上具有当前条件的文件 如何处理以上两种情况? 问题答案: 按照上面的注释中的“讨论”,在Cloud Function中,您可以使用方法返回的方法

  • 我正在使用Firebase函数和Firebase FiRecovery开发一个存储用户数据的API。 我想使用存储在字段中的属性来定位文档。这是Firebase文档,其中说明了如何实现相同的目标。 我想处理两种情况 > 如果没有符合当前条件的文件 如果有两份以上的现有条件文件 上述两种情况如何处理?