1

I'm trying to generate unique incremented ids for entities. For that purpose I have registered multiple ApplicationListeners for every entity type as:

public class Neo4JCustomerSaveListener implements ApplicationListener<BeforeSaveEvent<Customer>> {
    public void onApplicationEvent(BeforeSaveEvent<Customer> event) {
        ...
    }
}

definitions are like:

<!-- Listeners -->
<bean id="customerSaveListener" class="c.b.listener.Neo4JCustomerSaveListener" />
<bean id="employeeSaveListener" class="c.b.listener.Neo4JEmployeeSaveListener" />
<bean id="messageSaveListener" class="c.b.listener.Neo4JMessageSaveListener" />

As seen, BeforeSaveEvent is parametrized with Customer type. But the thing is, when a save event is about to happen for customer, other listeners are also triggered although tese listeners' BeforeSaveEvent is parametrized with different types, such as Employee or Message (while inheriting from the same Entity parent class)

Is this to be expected? And what should be my approach to this problem? First thing coming to mind is to use only one listener and differentiate inside with instanceOf ifs but this seems very ugly.

I'm using neo4j 1.9.M03, spring-data-neo4j 2.1.0.RC4 and spring 3.1.3

4

0 回答 0