Kotlin和Spring数据JPA生成PropertyReferenceException
我目前正在使用Kotlin 1.2和Spring Boot 2.0 M7以及Spring数据JPA。在这个项目中,我使用的是一个自定义的基本存储库,而不是JPARepository或PagingAndSortingRepository(真的没关系) 这是基本接口Kotlin和Spring数据JPA生成PropertyReferenceException,kotlin,spring-data-jpa,kotlin-interop,Kotlin,Spring Data Jpa,Kotlin Interop,我目前正在使用Kotlin 1.2和Spring Boot 2.0 M7以及Spring数据JPA。在这个项目中,我使用的是一个自定义的基本存储库,而不是JPARepository或PagingAndSortingRepository(真的没关系) 这是基本接口 @NoRepositoryBean interface BaseRepository<T, ID : Serializable> : Repository<T, ID> { fun <S : T&g
@NoRepositoryBean
interface BaseRepository<T, ID : Serializable> : Repository<T, ID> {
fun <S : T> save(entity: S): S
fun findOne(id: ID): T?
fun findAll(): List<T>
fun count(): Long
}
但一开始,我就犯了一个奇怪的错误
Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract java.lang.Object com.nokia.srandu.oms.corrviewer.db.repo.BaseRepository.findOne(java.io.Serializable)! No property findOne found for type Article!
.
.
.
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property findOne found for type Article!
我认为这与我的工作有关,但我能做些什么来解决这个问题呢?将接口传输到Java也没有帮助 存储库的方法名称约定在Spring Data 2.0中已更改:
fun findById(…):T?
->fun findById(…):可选
如果要继续获取简单的可空类型而不是可选的,请声明一个附加的或备用的查询方法
fun getById(…):T?
,它应该可以正常工作。存储库的方法名约定在Spring Data 2.0中已更改:
fun findById(…):T?
->fun findById(…):可选
如果您想继续获得一个简单的可空类型,而不是一个
可选的
,请声明一个附加的或备用的查询方法fun getById(…):T?
,它应该可以按预期工作。为什么要创建一个BaseRepository?Spring数据中有一个JPARepository,您可以使用。@SimonMartinelli实际上,如果我使用JPARepository,它仍然是相同的错误,但使用不同的方法。我没有使用JPARepository,因为我不想公开物理删除方法为什么要创建BaseRepository?Spring数据中有一个JPARepository,您可以使用。@SimonMartinelli实际上,如果我使用JPARepository,它仍然是相同的错误,但使用不同的方法。我没有使用JPARepository,因为我不想公开物理删除方法
@Entity
@Table(name = "article")
@Cacheable
data class Article (
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
var id: Int? = null,
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id", nullable = false)
var member: Member? = null,
@Column(name = "title", nullable = false, length = 200)
var title: String = "",
@Column(name = "content", nullable = false, length = 65535)
var content: String = "",
@Column(name = "last_modified", nullable = false, length = 19)
var lastModified: LocalDateTime = LocalDateTime.now(),
@Column(name = "deleted", nullable = false)
var deleted: Boolean = false,
@Column(name = "effective_start", length = 19)
var effectiveStart: LocalDateTime? = null,
@Column(name = "effective_end", length = 19)
var effectiveEnd: LocalDateTime? = null,
@Version
@Column(name = "version", nullable = false)
var version: Int = 0
): Serializable {
constructor() : this(null)
constructor(member: Member, title: String, content: String, lastModified: LocalDateTime, deleted: Boolean) : this(null, member, title, content, lastModified, deleted)
}
Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract java.lang.Object com.nokia.srandu.oms.corrviewer.db.repo.BaseRepository.findOne(java.io.Serializable)! No property findOne found for type Article!
.
.
.
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property findOne found for type Article!