gpt4 book ai didi

java - 由 : org. hibernate.hql.internal.ast.QuerySyntaxException : unexpected token: order near line 1, 第 17 列引起,原因不明

转载 作者:行者123 更新时间:2023-11-29 04:06:47 25 4
gpt4 key购买 nike

当我的存储库 bean 尝试初始化时,我的 JQL 查询出现语法错误消息:

 Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: order near line 1, column 17 [select distinct order from com.github.eljah.mental.domain.Order order left join fetch order.shipments left join fetch order.subscriptions] 

由Spring data repo中的这部分引起:

    @Query("select distinct order from Order order left join fetch order.shipments left join fetch order.subscriptions")

完整的输出附在下面。

Spring 数据存储库类:

@Repository
public interface OrderRepository extends JpaRepository<Order, Long>, JpaSpecificationExecutor<Order> {
@Query("select order from Order order where order.user.login = ?#{principal.username}")
List<Order> findByUserIsCurrentUser();

@Query(value = "select distinct order from Order order left join fetch order.shipments left join fetch order.subscriptions",
countQuery = "select count(distinct order) from Order order")
Page<Order> findAllWithEagerRelationships(Pageable pageable);

@Query("select distinct order from Order order left join fetch order.shipments left join fetch order.subscriptions")
List<Order> findAllWithEagerRelationships();

@Query("select order from Order order left join fetch order.shipments left join fetch order.subscriptions where order.id =:id")
Optional<Order> findOneWithEagerRelationships(@Param("id") Long id);

}

实体本身是:

@Entity
@Table(name = "jhi_order")
@org.springframework.data.elasticsearch.annotations.Document(indexName = "shipment", shards = 1, replicas = 0, refreshInterval = "-1")
public class Order implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
@org.springframework.data.elasticsearch.annotations.Field(type = FieldType.Keyword)
private Long id;

@Column(name = "created")
private ZonedDateTime created;

@Column(name = "paid")
private ZonedDateTime paid;

@Column(name = "processed")
private Boolean processed;

@Column(name = "md_order")
private String mdOrder;

@Column(name = "operation")
private String operation;

@ManyToOne(optional = false)
@NotNull
@JsonIgnoreProperties("orders")
private User user;

@ManyToMany
@JoinTable(name = "jhi_order_shipments",
joinColumns = @JoinColumn(name = "order_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "shipments_id", referencedColumnName = "id"))
private Set<Shipment> shipments = new HashSet<>();

@ManyToMany
@JoinTable(name = "jhi_order_subscriptions",
joinColumns = @JoinColumn(name = "order_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "subscriptions_id", referencedColumnName = "id"))
private Set<AccessSubscription> subscriptions = new HashSet<>();

setters/getters 被省略了。那么,那里出了什么问题?对于具有类似 JQL 查询的类似实体,我有类似的 SpringData 存储库,一切正常。或者“顺序”可能是 JQL 中的一种关键工作?

 | 2019-09-25 18:00:01.145 ERROR 8 --- [           main] o.h.hql.internal.ast.ErrorTracker        : line 1:119: unexpected token: order
mental-app_1 |
mental-app_1 | antlr.NoViableAltException: unexpected token: order
mental-app_1 | at org.hibernate.hql.internal.antlr.HqlBaseParser.joinPath(HqlBaseParser.java:1760)
mental-app_1 | at org.hibernate.hql.internal.antlr.HqlBaseParser.fromJoin(HqlBaseParser.java:1640)
mental-app_1 | at org.hibernate.hql.internal.antlr.HqlBaseParser.fromClause(HqlBaseParser.java:1355)
mental-app_1 | at org.hibernate.hql.internal.antlr.HqlBaseParser.selectFrom(HqlBaseParser.java:1063)
mental-app_1 | at org.hibernate.hql.internal.antlr.HqlBaseParser.queryRule(HqlBaseParser.java:748)
mental-app_1 | at org.hibernate.hql.internal.antlr.HqlBaseParser.selectStatement(HqlBaseParser.java:319)
mental-app_1 | at org.hibernate.hql.internal.antlr.HqlBaseParser.statement(HqlBaseParser.java:198)
mental-app_1 | at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:289)
mental-app_1 | at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:188)
mental-app_1 | at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:143)
mental-app_1 | at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:119)
mental-app_1 | at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
mental-app_1 | at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:153)
mental-app_1 | at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:611)
mental-app_1 | at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:720)
mental-app_1 | at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:104)
mental-app_1 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
mental-app_1 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
mental-app_1 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
mental-app_1 | at java.base/java.lang.reflect.Method.invoke(Unknown Source)
mental-app_1 | at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:350)
mental-app_1 | at com.sun.proxy.$Proxy173.createQuery(Unknown Source)
mental-app_1 | at org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.java:87)
mental-app_1 | at org.springframework.data.jpa.repository.query.SimpleJpaQuery.<init>(SimpleJpaQuery.java:63)
mental-app_1 | at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromMethodWithQueryString(JpaQueryFactory.java:76)
mental-app_1 | at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromQueryAnnotation(JpaQueryFactory.java:56)
mental-app_1 | at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$DeclaredQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:142)
mental-app_1 | at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:209)
mental-app_1 | at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:79)
mental-app_1 | at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lookupQuery(RepositoryFactorySupport.java:566)
mental-app_1 | at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$mapMethodsToQuery$1(RepositoryFactorySupport.java:559)
mental-app_1 | at java.base/java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
mental-app_1 | at java.base/java.util.Iterator.forEachRemaining(Unknown Source)
mental-app_1 | at java.base/java.util.Collections$UnmodifiableCollection$1.forEachRemaining(Unknown Source)
mental-app_1 | at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Unknown Source)
mental-app_1 | at java.base/java.util.stream.AbstractPipeline.copyInto(Unknown Source)
mental-app_1 | at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
mental-app_1 | at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
mental-app_1 | at java.base/java.util.stream.AbstractPipeline.evaluate(Unknown Source)
mental-app_1 | at java.base/java.util.stream.ReferencePipeline.collect(Unknown Source)
mental-app_1 | at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.mapMethodsToQuery(RepositoryFactorySupport.java:561)
mental-app_1 | at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$new$0(RepositoryFactorySupport.java:551)
mental-app_1 | at java.base/java.util.Optional.map(Unknown Source)
mental-app_1 | at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:551)
mental-app_1 | at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:324)
mental-app_1 | at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:297)
mental-app_1 | at org.springframework.data.util.Lazy.getNullable(Lazy.java:211)
mental-app_1 | at org.springframework.data.util.Lazy.get(Lazy.java:94)
mental-app_1 | at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:300)
mental-app_1 | at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:121)
mental-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1837)
mental-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774)
mental-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593)
mental-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
mental-app_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
mental-app_1 | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
mental-app_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
mental-app_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
mental-app_1 | at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277)
mental-app_1 | at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1251)
mental-app_1 | at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1171)
mental-app_1 | at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857)
mental-app_1 | at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760)
mental-app_1 | at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:218)
mental-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1341)
mental-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1187)
mental-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
mental-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
mental-app_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
mental-app_1 | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
mental-app_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
mental-app_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
mental-app_1 | at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:845)
mental-app_1 | at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877)
mental-app_1 | at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
mental-app_1 | at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
mental-app_1 | at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:742)
mental-app_1 | at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:389)
mental-app_1 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:311)
mental-app_1 | at com.github.eljah.mental.MentalApp.main(MentalApp.java:63)
mental-app_1 |
mental-app_1 | 2019-09-25 18:00:01.153 WARN 8 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'orderQueryService' defined in file [/app/classes/com/github/eljah/mental/service/OrderQueryService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List com.github.eljah.mental.repository.OrderRepository.findAllWithEagerRelationships()!
mental-app_1 | 2019-09-25 18:00:01.361 ERROR 8 --- [ main] o.s.boot.SpringApplication : Application run failed
mental-app_1 |
mental-app_1 | org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'orderQueryService' defined in file [/app/classes/com/github/eljah/mental/service/OrderQueryService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List com.github.eljah.mental.repository.OrderRepository.findAllWithEagerRelationships()!
mental-app_1 | at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:769)
mental-app_1 | at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:218)
mental-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1341)
mental-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1187)
mental-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
mental-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
mental-app_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
mental-app_1 | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
mental-app_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
mental-app_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
mental-app_1 | at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:845)
mental-app_1 | at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877)
mental-app_1 | at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
mental-app_1 | at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
mental-app_1 | at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:742)
mental-app_1 | at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:389)
mental-app_1 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:311)
mental-app_1 | at com.github.eljah.mental.MentalApp.main(MentalApp.java:63)
mental-app_1 | Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List com.github.eljah.mental.repository.OrderRepository.findAllWithEagerRelationships()!
mental-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778)
mental-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593)
mental-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
mental-app_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
mental-app_1 | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
mental-app_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
mental-app_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
mental-app_1 | at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277)
mental-app_1 | at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1251)
mental-app_1 | at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1171)
mental-app_1 | at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857)
mental-app_1 | at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760)
mental-app_1 | ... 17 common frames omitted
mental-app_1 | Caused by: java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List com.github.eljah.mental.repository.OrderRepository.findAllWithEagerRelationships()!
mental-app_1 | at org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.java:93)
mental-app_1 | at org.springframework.data.jpa.repository.query.SimpleJpaQuery.<init>(SimpleJpaQuery.java:63)
mental-app_1 | at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromMethodWithQueryString(JpaQueryFactory.java:76)
mental-app_1 | at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromQueryAnnotation(JpaQueryFactory.java:56)
mental-app_1 | at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$DeclaredQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:142)
mental-app_1 | at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:209)
mental-app_1 | at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:79)
mental-app_1 | at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lookupQuery(RepositoryFactorySupport.java:566)
mental-app_1 | at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$mapMethodsToQuery$1(RepositoryFactorySupport.java:559)
mental-app_1 | at java.base/java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
mental-app_1 | at java.base/java.util.Iterator.forEachRemaining(Unknown Source)
mental-app_1 | at java.base/java.util.Collections$UnmodifiableCollection$1.forEachRemaining(Unknown Source)
mental-app_1 | at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Unknown Source)
mental-app_1 | at java.base/java.util.stream.AbstractPipeline.copyInto(Unknown Source)
mental-app_1 | at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
mental-app_1 | at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
mental-app_1 | at java.base/java.util.stream.AbstractPipeline.evaluate(Unknown Source)
mental-app_1 | at java.base/java.util.stream.ReferencePipeline.collect(Unknown Source)
mental-app_1 | at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.mapMethodsToQuery(RepositoryFactorySupport.java:561)
mental-app_1 | at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$new$0(RepositoryFactorySupport.java:551)
mental-app_1 | at java.base/java.util.Optional.map(Unknown Source)
mental-app_1 | at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:551)
mental-app_1 | at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:324)
mental-app_1 | at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:297)
mental-app_1 | at org.springframework.data.util.Lazy.getNullable(Lazy.java:211)
mental-app_1 | at org.springframework.data.util.Lazy.get(Lazy.java:94)
mental-app_1 | at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:300)
mental-app_1 | at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:121)
mental-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1837)
mental-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774)
mental-app_1 | ... 28 common frames omitted
mental-app_1 | Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: order near line 1, column 17 [select distinct order from com.github.eljah.mental.domain.Order order left join fetch order.shipments left join fetch order.subscriptions]
mental-app_1 | at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:138)
mental-app_1 | at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:181)
mental-app_1 | at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:188)
mental-app_1 | at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:729)
mental-app_1 | at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:104)
mental-app_1 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
mental-app_1 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
mental-app_1 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
mental-app_1 | at java.base/java.lang.reflect.Method.invoke(Unknown Source)
mental-app_1 | at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:350)
mental-app_1 | at com.sun.proxy.$Proxy173.createQuery(Unknown Source)
mental-app_1 | at org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.java:87)
mental-app_1 | ... 57 common frames omitted
mental-app_1 | Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: order near line 1, column 17 [select distinct order from com.github.eljah.mental.domain.Order order left join fetch order.shipments left join fetch order.subscriptions]
mental-app_1 | at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:74)
mental-app_1 | at org.hibernate.hql.internal.ast.ErrorTracker.throwQueryException(ErrorTracker.java:93)
mental-app_1 | at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:296)
mental-app_1 | at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:188)
mental-app_1 | at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:143)
mental-app_1 | at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:119)
mental-app_1 | at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
mental-app_1 | at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:153)
mental-app_1 | at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:611)
mental-app_1 | at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:720)
mental-app_1 | ... 65 common frames omitted

最佳答案

单词 order(您似乎试图在查询中用作变量名)是 JPQL 保留字。请改用o,我强烈建议您考虑将“当前用户”外部化,以便您将用户或用户ID 作为参数传入并在别处解析;在 @Query 中执行此操作会引入难以测试的硬耦合。

关于java - 由 : org. hibernate.hql.internal.ast.QuerySyntaxException : unexpected token: order near line 1, 第 17 列引起,原因不明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58104588/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com