[英]EclipseLink JPA uses a non-entity as target entity in the relationship attribute
[英]JPA: Is it possible for the target of a relationship to be a non entity?
以下代码在Kotlin中。
我有一个TestExecutionSummary
实体
@Entity
class TestExecutionSummary : Serializable {
@EmbeddedId
lateinit var id: TestExecutionId
...
@OneToMany(cascade = [CascadeType.ALL], mappedBy = "testExecutionSummary")
var failures: List<TestFailure> = mutableListOf()
}
@Embeddable
data class TestExecutionId(
var stepExecutionId: Long,
var jobExecutionId: Long
) : Serializable
和一个TestFailure
实体
@Entity
class TestFailure : Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
var id: Long? = null
@Column(length = 999)
lateinit var testId: String
@JoinColumns(
JoinColumn(name = "stepExecutionId", referencedColumnName = "stepExecutionId"),
JoinColumn(name = "jobExecutionId", referencedColumnName = "jobExecutionId")
)
@ManyToOne
lateinit var testExecutionSummary: TestExecutionSummary
@Column(length = 999)
var message: String? = null
}
这很好用,但令我TestFailure
是TestFailure
没有独立存在,并且实际上没有资格作为实体IMO。 是否可以在不使TestFailure
成为实体的情况下保持所示的关系?
JPA 2.0具有ElementCollection ,这正是我想要的。
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(
name = "TEST_FAILURE",
joinColumns = [
JoinColumn(name = "stepExecutionId", referencedColumnName = "stepExecutionId"),
JoinColumn(name = "jobExecutionId", referencedColumnName = "jobExecutionId")
]
)
var failures: List<TestFailure> = mutableListOf()
@Embeddable
class TestFailure : Serializable {
@Column(length = 999)
lateinit var testId: String
@Column(length = 999)
var message: String? = null
}
您要求使用@Embeddable,但不适用于@OneToMany。 解决方法,请参阅在JPA中将单个表映射到可嵌入集合。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.