我试图对扩展抽象类的实体运行ST_DWithin查询。
我针对更传统的模型测试了查询,并且运行效果很好。
我要对其运行查询的实体。
@Entity
actual data class SecRoleCheeseBuyer(
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "sec_role_id")
actual override val secRole: SecRole,
actual var latitude: Double? = null,
actual var longitude: Double? = null,
val point: Point
) : SecRoleDetail() {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "sec_user_id")
actual override var secUser: SecUser? = null
actual override fun toDtoMin() = this.createDtoMin(detail = this.secRole.secRoleName.name)
actual override fun toDto(): SecRoleCheeseBuyerDto {
val dto = SecRoleCheeseBuyerDto(
secRole = this.secRole.toDtoMin(),
secUser = this.secUser?.toDtoMin()!!
)
this.addSuperDataToDTO(dto)
return dto
}
}
抽象类
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "discriminator", discriminatorType = DiscriminatorType.STRING)
actual abstract class SecRoleDetail : RestModel() {
actual abstract val secRole: SecRole
actual abstract var secUser: SecUser?
}
查询
interface SecRoleDetailCheeseBuyerRepository : JpaRepository<SecRoleCheeseBuyer, Long>{
@Query(value = """
SELECT *
FROM sec_role_Cheese_buyer
WHERE ST_DWithin(point, cast(ST_MakePoint(:longitude,:latitude) as geography), :distance)
""", nativeQuery = true) // distance is meters
fun fetchByDistance(
@Param("distance") distance: Double,
@Param("longitude") longitude: Double,
@Param("latitude") latitude: Double
): List<SecRoleCheeseBuyer>
}
每次都会抛出一个org.hibernate.exception.SQLGrammarException,我有一个丑陋的解决方法,但我想知道我在做什么错。