Cascades And Compass

Have not blogged for some time, but it does not mean that stabilizing and adding new features to Compass stopped. One of the new features in Compass is support for cascading operations. When using OSEM, Compass can now cascade create/save/delete operations to both reference and component mappings.

In the mapping definitions (either xml or annotations) one can configure which operations will be cascaded. An interesting side-effect of the cascading feature is the ability to perform operation on non-root objects. If previously Compass threw an exception when a non-root object was being created/saved/deleted in Compass, Compass will now throw an exception if it is non root *and* has no cascading relationships. This means that operations on non root objects with cascading mapping can be performed.

For a concrete example, if we have a Person and Address class, we might want to cascade operation performed on the Address class to the relevant Person (Address is probably defined as root=false in Compass). Note, this will mean that Address should have a reference to Person (otherwise Compass won’t know how to fetch the applicable Person). This is very relevant in cases where Compass integrates with ORM tools where Person and Address might be stored on two different tables, and changes to Address won’t trigger a change to Person (thus not performing the operation using Compass injected ORM event listeners).

5 Responses to “Cascades And Compass”

  1. Tom Says:

    Has anyone used Compass with SEAM? and written anything about their experience?

  2. Craig Baker Says:

    I’m interested in the performance overheads if I enable cascading references. If for example I perform an update on the Address, will this trigger compass to re-index the entire root object, Person in this example and all its children or just the modified child.

  3. Shay Banon Says:

    Currently in Compass, all the children will get reindexed.

  4. Mark Says:

    Hi, Shay -

    Thanks for all your hard work on this - I’m excited to get cascading working. I’ve tried to configure my JPA app to use it and I’m not quite sure what the correct approach is. Below are two simplified domain objects that mirror your “Person/Address” example above - am I wrongly putting the cascade setting on the Client reference in the ClientAddress object? Should I have a @SearchableComponent annotation on the ClientAddress reference in the Client object?

    Any advice on this would be much appreciated.

    Thanks!

    @Searchable(alias = “client”)
    public class Client {
    @SearchableId
    private Long id;

    @SearchableProperty
    private String name;

    private ClientAddress clientAddress;
    }

    @Searchable(root = false)
    public class ClientAddress {
    private Long id;

    @SearchableProperty
    private String streetAddress;

    @SearchableProperty
    private String city;

    @SearchableComponent(cascade = Cascade.ALL)
    private Client client;
    }

  5. Mark Says:

    Ah…figured it out. In case anyone else is interested, change:

    private ClientAddress clientAddress;

    to

    @SearchableComponent
    private ClientAddress clientAddress;

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>