52 lines
1.3 KiB
Java
Executable File
52 lines
1.3 KiB
Java
Executable File
package com.ankurm.hibernatedemo.immutable;
|
|
|
|
import jakarta.persistence.CascadeType;
|
|
import jakarta.persistence.Entity;
|
|
import jakarta.persistence.FetchType;
|
|
import jakarta.persistence.GeneratedValue;
|
|
import jakarta.persistence.GenerationType;
|
|
import jakarta.persistence.Id;
|
|
import jakarta.persistence.OneToMany;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import org.hibernate.annotations.Immutable;
|
|
|
|
/**
|
|
* A MUTABLE parent entity (no {@code @Immutable} on the class) whose collection is marked
|
|
* {@code @Immutable}. This isolates the collection-level annotation's own behaviour, per the
|
|
* article's "Advanced Usage: Immutable Collections" section, from the entity-level one.
|
|
*/
|
|
@Entity
|
|
public class RateWithAuditTrail {
|
|
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "rate_audit_seq")
|
|
private Long id;
|
|
|
|
private String pair;
|
|
|
|
@Immutable
|
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
|
private List<AuditTrail> auditTrails = new ArrayList<>();
|
|
|
|
protected RateWithAuditTrail() {
|
|
// JPA
|
|
}
|
|
|
|
public RateWithAuditTrail(String pair) {
|
|
this.pair = pair;
|
|
}
|
|
|
|
public Long getId() {
|
|
return id;
|
|
}
|
|
|
|
public String getPair() {
|
|
return pair;
|
|
}
|
|
|
|
public List<AuditTrail> getAuditTrails() {
|
|
return auditTrails;
|
|
}
|
|
}
|