Kotlin Spring Boot – 如何在CrudRepository中跳过类中的属性?

huangapple go评论65阅读模式
英文:

Kotlin Spring Boot - How do you skip a property in a class with CrudRepository?

问题

如何使CrudRepository跳过在数据库表中创建字段?也就是说,

@Table
class Property(@Id val id: String?, val name: String, val objectType: String, currentValue: String?) {
}

假设我只想创建一个具有id和name的表,跳过其他字段。这是可能的吗?

谢谢!

英文:

hoping this is a easy question. How do you get the CrudRepository to skip making a field in the db table? i.e.

@Table
class Property(@Id val id: String?, val name: String, val objectType: String, currentValue: String?) {
}

lets say I only wanted a table with id & name created, skipping the others. Is that possible?

Thank you!

答案1

得分: 1

你正在寻找 @Transient 注解。将该注解放在你的字段上,Hibernate 将不会持久化它。

更多信息:https://stackoverflow.com/questions/44272844/kotlin-jpa-and-transient

英文:

You are seeking @Transient annotation.
Put the annotation above your field and Hibernate doesn’t persist it.

For more: https://stackoverflow.com/questions/44272844/kotlin-jpa-and-transient

答案2

得分: 0

@org.springframework.data.annotation.Transient

英文:

I had to do this to get it to work, but Transient is correct!

@org.springframework.data.annotation.Transient 

huangapple
  • 本文由 发表于 2023年3月7日 09:29:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75657287.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定