Imagine I have two entities `A` and `A_Log` with r...
# spring
u
Imagine I have two entities
A
and
A_Log
with relations:
@Entity data class A (val log: A_Log)
@Entity data class A_Log(val a: A, val price: Int)
And a method which persists them:
Copy code
@Transactional fun persist(val dto: PriceDto) {
	val a: A = A(???)
	val log: A_Log = (a, price = dto.price)

	// persist methods
}
I think the problem is clear, any way to solve this egg-or-chicken problem except making fields nullable and using (
!!
) elsewhere in code?
j
The answer to your question is probably not in the structure of your classes but in the behaviour you need. Do you really need to have a bi-directional relationship for storage?
u
@Jaco seems like yes, because I need to have reference on parent from every log entity, and having last log reference on the main eitnty
j
Assuming you could do that, what would happen if you call equals() or hashCode() or toString() on one of those objects?