79808325

Date: 2025-11-03 21:22:52
Score: 0.5
Natty:
Report link

Envers might use the stable ValueObject.id as the primary identifier to track changes, completely bypassing the composite key issue with @ElementCollection

@Entity
@Audited
class ValueObject {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    private String propertyA;
    private Integer propertyB;
}

@Entity
@Audited
class ParentEntity {
    @Id
    private Long id;

    @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
    @JoinColumn(name = "parent_id")
    @OrderColumn(name = "position")
    private List<ValueObject> values = new ArrayList<>();
}

Changed @Embeddable to @Entity

Added @GeneratedValue

Changed @ElementCollection to @OneToMany

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @ElementCollectionChanged
  • User mentioned (0): @Embeddable
  • User mentioned (0): @Entity
  • User mentioned (0): @GeneratedValue
  • User mentioned (0): @ElementCollection
  • User mentioned (0): @OneToMany
  • Low reputation (0.5):
Posted by: Max