package; import Transaction; import javax.persistence.*; import java.io.Serializable; import java.util.Date; @Entity(name = "TransactionEvent") @Table(name = "TransactionEvent") @DiscriminatorColumn(name = "event_type") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) public abstract class TransactionEvent extends Event implements Serializable { @Id @GeneratedValue private Long id; @OneToOne(targetEntity = Transaction.class, cascade = CascadeType.ALL, orphanRemoval = true) private Transaction transaction; @Column(name = "created") private Date created = new Date(); @Column(name = "updated") private Date updated; public Long getId() { return id; } public Date getCreated() { return created; } public void setCreated(Date created) { this.created = created; } public Date getUpdated() { return updated; } @PrePersist private void onPrePersist() { this.created = new Date(); } @PreUpdate private void onPreUpdate() { this.updated = new Date(); } public Transaction getTransaction() { return transaction; } public void setTransaction(Transaction transaction) { this.transaction = transaction; } @Override public String toString() { return "TransactionEvent{" + "transaction=" + transaction + ", id=" + id + '}'; } }