Kotlin,JPA和@Transient
我有一个实体类,我已经从Java迁移到Kotlin。 其中一个属性( inetAddress
)用@Transient
注释,以防止它被持久化到关系数据库。 但是,JPA(Hibernate实现)没有看到这个注释,并把它放在数据库中,因为它是自己的字段。 当这个类用Java编写时,这一切都可以正常工作。
有谁知道如何正确注释这个Kotlin类,以便JPA / Hibernate将看到@Transient
注释,而不是将inetAddress
属性放在数据库中?
package infr.audio.model import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonProperty import infr.audio.messages.InetAddressWrapper import java.io.Serializable import java.net.InetAddress import javax.persistence.Column import javax.persistence.Entity import javax.persistence.GeneratedValue import javax.persistence.Id import javax.persistence.NamedQueries import javax.persistence.NamedQuery import javax.persistence.Table @Entity @Table(name = "DIS_JOCKEY") @NamedQueries(NamedQuery(name = "DisJockeyInfo.find", query = "SELECT m FROM DisJockeyInfo m"), NamedQuery(name = "DisJockeyInfo.findByReservationId", query = "SELECT m FROM DisJockeyInfo m WHERE m.reservationId = :reservationId"), NamedQuery(name = "DisJockeyInfo.findByReservationIdAndName", query = "SELECT m FROM DisJockeyInfo m WHERE m.reservationId = :reservationId AND m.name = :name"), NamedQuery(name = "DisJockeyInfo.findMaxDisEntityIdByReservationId", query = "SELECT MAX(m.disEntityId) FROM DisJockeyInfo m WHERE m.reservationId = :reservationId"), NamedQuery(name = "DisJockeyInfo.findActive", query = "SELECT m FROM DisJockeyInfo m WHERE m.disEntityId IS NOT NULL"), NamedQuery(name = "DisJockeyInfo.findActiveByInetAddress", query = "SELECT m FROM DisJockeyInfo m WHERE m.inetAddress = :inetAddress AND m.disEntityId IS NOT NULL"), NamedQuery(name = "DisJockeyInfo.findActiveByReservationId", query = "SELECT m FROM DisJockeyInfo m WHERE m.reservationId = :reservationId AND m.disEntityId IS NOT NULL"), NamedQuery(name = "DisJockeyInfo.deleteInactive", query = "DELETE FROM DisJockeyInfo m WHERE m.id = :id AND m.disEntityId IS NULL")) data class DisJockeyInfo( @get:Id @get:GeneratedValue(strategy = GenerationType.IDENTITY) @get:Column(name = "ID") var id: Long, @get:Column(name = "RESERVATION_ID") var reservationId: String?, @get:Column(name = "NAME") var name: String?, @get:Column(name = "DIS_ENTITY_ID") var disEntityId: Long?, @get:java.beans.Transient @get:JsonIgnore @field:Transient var inetAddress: InetAddress? ) : GenericEntity, Serializable { var inetAddressString: String? @Column(name = "INET_ADDRESS") @JsonProperty("inetAddress") get() = if (inetAddress != null) InetAddressWrapper(inetAddress).encodedInetAddress else null set(inetAddressString) { inetAddress = if (inetAddressString != null) InetAddressWrapper(inetAddressString).inetAddress else null } constructor() : this(id = 0L, reservationId = null, name = null, disEntityId = null, inetAddress = null) {} companion object { /** Serial version */ private val serialVersionUID = 2027355982760360935L } }
你注释的领域,而不是注释吸气剂。 请注意,您的getter批注使用不正确的types( java.beans.Transient
)而不是正确的javax.persistence.Transient
。