嗨,这是我的资料库
@Repository
interface GuestRepository : JpaRepository<Guest, Long> {
@Query("from Guests g where g.date>=:fromDate and g.date<=:toDate ",nativeQuery = true)
fun findInPeriod(
@Param("fromDate") fromDate: Date
, @Param("toDate") toDate: Date
, pageRequest: Pageable
): Page<Guest>
}
这是我的客人对象
@Entity
@Table(name = "Guests")
data class Guest(
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "guest_seq")
@SequenceGenerator(name = "guest_seq", sequenceName = "guest_seq", allocationSize = 1)
val id: Long=0
,
@Column(length = 50, unique = true)
@NotNull
@Size(min = 4, max = 50)
val userName: String="username"
, val firstName: String?=null
, val lastName: String?=null
,
@Temporal(TemporalType.TIMESTAMP)
@NotNull
val date: Date=Date()
)
我使用spring和h2,但是当我运行我的应用程序时,它向我显示此错误消息
org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "FROM GUESTS G WHERE[*] G.DATE>=? AND G.DATE<=? LIMIT ? "; expected "(, USE, RIGHT, LEFT, FULL, INNER, JOIN, CROSS, NATURAL, ,, SELECT"; SQL statement:
答案 0 :(得分:0)
使用nativeQuery = true
告诉Spring Data JDBC将您的查询视为本机(即SQL)查询。
但是您提供的查询不是合法的SQL。 它看起来非常类似于HQL,它是JPQL的一种特定于Hibernate的方言。
要解决此问题,请删除nativeQuery = true
部分或使用SQL