如何用hibernate panache更新属性?

xwbd5t1u  于 2021-07-04  发布在  Java
关注(0)|答案(0)|浏览(537)

我有以下ddl定义:

  1. @Entity
  2. data class Interest(
  3. @JsonIgnore
  4. @ManyToMany(mappedBy = "interests")
  5. var account: List<Account> = listOf(),
  6. var description: String = "") : PanacheEntity()
  7. @Entity
  8. data class Account(@field:Id var uuid: UUID? = null,
  9. @ManyToOne(fetch = FetchType.LAZY) var gender: Gender? = null,
  10. var birthday: Long = 0,
  11. @ManyToMany(fetch = FetchType.LAZY, cascade = [CascadeType.PERSIST])
  12. @JoinTable(
  13. name = "account_interests",
  14. joinColumns = [JoinColumn(name = "account_id")],
  15. inverseJoinColumns = [JoinColumn(name = "interest_id")]
  16. )
  17. var interests: List<Interest> = listOf()) : PanacheEntityBase

正如您在定义中看到的,我将hibernate orm与panache结合使用,它遵循活动记录模式。此外,我还创造了 AccountRepository :

  1. @ApplicationScoped
  2. class AccountRepository : PanacheRepository<Account> {
  3. @Transactional
  4. fun create(newAcc: Account): Account =
  5. persist(newAcc).let { newAcc }
  6. fun read(id: UUID): Account? =
  7. find("uuid", id).firstResult()
  8. @Transactional
  9. fun updateInterests(id: UUID, i: Interests): Int {
  10. println(i)
  11. return update("interests = ?1 where uuid = ?2", i, id)
  12. }
  13. }

我的问题是方法 updateInterests . 它引发异常:

  1. RESTEASY002020: Unhandled asynchronous exception, sending back 500: org.jboss.resteasy.spi.ApplicationException: java.lang.IllegalArgumentException: Parameter value [Interest(account=[], description=Luxury)] did not match expected type [java.util.Collection (n/a)]

即将到来的 interests 有效载荷为:

  1. [Interest(account=[], description=Luxury), Interest(account=[], description=Travel)]

如何更新帐户的属性 interests 正确地?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题