0

Imagine an Entity A has a non-mandatory one-to-one relationship with itself, say something like the diagram below. diagram

Do I write sourceTransaction and destinationTransaction as: public DepositAccountTransaction sourceTransaction; public DepositAccountTransaction destinationTransaction; without any annotations?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

1 Answers1

2

No you always will need the annotation. If it is optional:

@OneToOne(optional = true)
private DepositAccountTransaction destinationTransaction;

I wouldn't declare any property as public btw. You may want to use projectlombok to generate getters and setters.

Christian
  • 3,503
  • 1
  • 26
  • 47