1
votes

I have a composition pattern where a parent object has a list of child objects, e.g., Order and LineItem.

It behaves similar to cascading with delete orphans, but the child objects are @Embeddables instead of @Entities, and don't get their own IDs - they're always managed through their parent object.

In JPA I could do something like this to ensure that whenever I save an Order, the collection of LineItems synchronize, including deleting removed items:

public class Order {
  @ElementCollection
  @CollectionTable(...)

  private Set<LineItem> items;

}

In Grails, what's the equivalent?

I can do hasMany with cascade all-delete-orphan but would prefer if there were a similar way for the child objects to not have their own IDs (basically, not be entities).

1

1 Answers

1
votes

You can use static embedded in Order. Refer this.