【发布时间】:2018-06-21 05:30:06
【问题描述】:
请注意:不是this one的骗子...我遇到了同样的例外,但原因不同!
JPA/Hibernate 在这里,被一个用 Groovy 编写的 Spring Boot 应用程序使用(Groovy 无关紧要;只是为了更好的衡量而提及它)。我有以下 3 个实体:
@Entity(name = 'accounts')
class Account {
@Id
@Column(name='account_id')
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id
@Column(name='account_ref_id')
String refId
@Column(name = 'account_email')
@NotEmpty
String email
@Column(name = 'account_username')
String username
}
@Entity(name = 'security_token_types')
class SecurityTokenType {
@Id
@Column(name='security_token_type_id')
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id
@Column(name='security_token_type_ref_id')
String refId
@Column(name='security_token_type_name')
String name
@Column(name='security_token_type_label')
String label
@Column(name='security_token_type_description')
String description
}
@Entity(name = 'security_tokens')
class SecurityToken {
@Id
@Column(name='security_token_id')
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id
@Column(name='security_token_ref_id')
String refId
@OneToOne(fetch = FetchType.EAGER, cascade = [CascadeType.PERSIST, CascadeType.MERGE])
@JoinColumn(name = 'account_id', referencedColumnName = 'account_id')
Account account
@Column(name = 'security_token')
String token
@OneToOne(fetch = FetchType.EAGER, cascade = [CascadeType.PERSIST, CascadeType.MERGE])
@JoinColumn(name = 'security_token_type_id', referencedColumnName = 'security_token_type_id')
SecurityTokenType type
@Column(name = 'security_token_generated_on')
Date generatedOn
}
还有一个SecurityPersistor (DAO) 存储库:
interface SecurityTokenPersistor extends CrudRepository<SecurityToken, Long> {
@Query("FROM security_tokens st INNER JOIN security_token_types stt ON st.security_token_type_id = stt.security_token_type_id WHERE stt.security_token_type_label = :type AND st.account_id = :accountId")
Set<SecurityToken> findTokensByAccountAndType(@Param('accountId') Long accountId, @Param('type') String type)
}
在运行时我得到这些:
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: Path expected for join! [FROM com.armbet.ws.domain.entities.SecurityToken st INNER JOIN security_token_types stt ON st.security_token_type_id = stt.security_token_type_id WHERE stt.security_token_type_label = :type AND st.account_id = :accountId]
at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:74)
at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:91)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:268)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:190)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:142)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:115)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:76)
我觉得我在SecurityPersistor#findTokensByAccountAndType 方法中的JOIN 语法是错误的。有什么想法会出错吗?
【问题讨论】:
-
谢谢@pvpkiran 我也看到了,但是如果您阅读问题描述以及单独的答案,您会发现我已经尝试过该解决方案。相同的异常/错误消息,两个不同的问题!
标签: hibernate jpa spring-boot spring-data