Q:

spring-data-neo4j: Can't create two relationship properties with same label

Using spring-data-neo4j, I am not able to set up two relationship properties in the same class with the same label.
The following code can be found in my branch https://github.com/spencerhrob/gs-accessing-data-neo4j/tree/same-name-relationships.
Person.java:
@NodeEntity
public class Person {

    @GraphId Long id;
    public String name;

    public Person() {}
    public Person(String name) { this.name = name; }

    @RelatedTo(type="MEMBER_OF", direction=Direction.OUTGOING)
    Dojo dojo;

    @RelatedTo(type="MEMBER_OF", direction=Direction.OUTGOING)
    MailingList mailingList;

    public void setDojo(Dojo dojo) {
        this.dojo = dojo;
    }
    public void setMailingList(MailingList mailingList) {
        this.mailingList = mailingList;
    }

    @Override
    public String toString() {
        return "Person [name=" + name + "]";
    }
}

Dojo.java:
@NodeEntity
public class Dojo {

    @GraphId Long id;
    public String name;

    public Dojo() { }
    public Dojo(String name) { this.name = name; }

    @Override
    public String toString() {
        return "Dojo [name=" + name + "]";
    }
}

MailingList.java:
@NodeEntity
public class MailingList {

    @GraphId Long id;
    public String name;

    public MailingList() { }
    public MailingList(String name) { this.name = name; }

    @Override
    public String toString() {
        return "MailingList [name=" + name + "]";
    }

}

Application.java:
@Configuration
@EnableNeo4jRepositories(basePackages = "hello")
public class Application extends Neo4jConfiguration implements CommandLineRunner {

    public Application() {
        setBasePackage("hello");
    }

    @Bean
    GraphDatabaseService graphDatabaseService() {
        return new GraphDatabaseFactory().newEmbeddedDatabase("accessingdataneo4j.db");
    }

    @Autowired
    PersonRepository personRepository;

    @Autowired
    GraphDatabase graphDatabase;

    public void run(String... args) throws Exception {
        Transaction tx = graphDatabase.beginTx();
        try {
            Person linus = new Person("Linus");
            linus.setDojo(new Dojo("Coding Dojo"));
            linus.setMailingList(new MailingList("Kernel Mailing List"));

            personRepository.save(linus);

            tx.success();
        } finally {
            tx.close();
        }
    }

    public static void main(String[] args) throws Exception {
        FileUtils.deleteRecursively(new File("accessingdataneo4j.db"));

        SpringApplication.run(Application.class, args);
    }
}

When I run this code, I get the following exception:

java.lang.IllegalStateException: Failed to execute CommandLineRunner
    at
  org.springframework.boot.SpringApplication.runCommandLineRunners(SpringApplication.java:680)
    at
  org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:695)
    at
  org.springframework.boot.SpringApplication.run(SpringApplication.java:321)
    at
  org.springframework.boot.SpringApplication.run(SpringApplication.java:952)
    at
  org.springframework.boot.SpringApplication.run(SpringApplication.java:941)
    at hello.Application.main(Application.java:56) Caused by:
  org.springframework.data.mapping.model.MappingException: Setting
  property mailingList to Dojo [name=null] on Person [name=Linus]   at
  org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.setProperty(SourceStateTransmitter.java:85)
    at
  org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.copyEntityStatePropertyValue(SourceStateTransmitter.java:91)
    at
  org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.access$000(SourceStateTransmitter.java:40)
    at
  org.springframework.data.neo4j.support.mapping.SourceStateTransmitter$2.doWithAssociation(SourceStateTransmitter.java:61)
    at
  org.springframework.data.mapping.model.BasicPersistentEntity.doWithAssociations(BasicPersistentEntity.java:324)
    at
  org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.copyPropertiesFrom(SourceStateTransmitter.java:57)
    at
  org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.loadEntity(Neo4jEntityConverterImpl.java:112)
    at
  org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.read(Neo4jEntityConverterImpl.java:104)
    at
  org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedConverter.read(Neo4jEntityPersister.java:170)
    at
  org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.createEntityFromState(Neo4jEntityPersister.java:189)
    at
  org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.persist(Neo4jEntityPersister.java:244)
    at
  org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.persist(Neo4jEntityPersister.java:231)
    at
  org.springframework.data.neo4j.support.Neo4jTemplate.save(Neo4jTemplate.java:356)
    at
  org.springframework.data.neo4j.support.Neo4jTemplate.save(Neo4jTemplate.java:350)
    at
  org.springframework.data.neo4j.repository.AbstractGraphRepository.save(AbstractGraphRepository.java:91)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at
  sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at
  sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)     at
  org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:405)
    at
  org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:390)
    at
  org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:344)
    at
  org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at
  org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
    at
  org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
    at
  org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
    at
  org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at
  org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
    at
  org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at
  org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
    at com.sun.proxy.$Proxy43.save(Unknown Source)  at
  hello.Application.run(Application.java:44)    at
  org.springframework.boot.SpringApplication.runCommandLineRunners(SpringApplication.java:677)
    ... 5 common frames omitted Caused by:
  org.springframework.core.convert.ConverterNotFoundException: No
  converter found capable of converting from type hello.Dojo to type
  hello.MailingList     at
  org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:291)
    at
  org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:177)
    at
  org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:158)
    at
  org.springframework.data.mapping.model.BeanWrapper.getPotentiallyConvertedValue(BeanWrapper.java:155)
    at
  org.springframework.data.mapping.model.BeanWrapper.setProperty(BeanWrapper.java:75)
    at
  org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.setProperty(SourceStateTransmitter.java:83)
    ... 37 common frames omitted

There's a lot there but the real error is that Spring is trying to convert a Dojo into a MailingList.
Meanwhile, this code works if I name the relationships with different names (as in my branch https://github.com/spencerhrob/gs-accessing-data-neo4j/tree/different-name-relationships). Person.java:
@NodeEntity
public class Person {

    @GraphId Long id;
    public String name;

    public Person() {}
    public Person(String name) { this.name = name; }

    @RelatedTo(type="MEMBER_OF_DOJO", direction=Direction.OUTGOING)
    Dojo dojo;

    @RelatedTo(type="MEMBER_OF_LIST", direction=Direction.OUTGOING)
    MailingList mailingList;

    public void setDojo(Dojo dojo) {
        this.dojo = dojo;
    }
    public void setMailingList(MailingList mailingList) {
        this.mailingList = mailingList;
    }

    @Override
    public String toString() {
        return "Person [name=" + name + "]";
    }
}

Without any changes to Application.java (or to Dojo.java or MailingList.java), this code executes successfully.
My understanding from this example is that spring-data-neo4j will not allow a class to have two properties that have the same label. In certain cases different relationships need to have the same label--for example, to conform to modeling standards. Is it possible to set up more than one relationship with the same name in spring-data-neo4j? If so, how?

A:

I've found the answer to this question. What I was looking for is the "enforceTargetType" attribute as described in the documentation. 
I've made a branch of the repository that uses this fix. It is found at https://github.com/spencerhrob/gs-accessing-data-neo4j/tree/same-name-enforce-target.
Person.java:
@NodeEntity
public class Person {

    @GraphId Long id;
    public String name;

    public Person() {}
    public Person(String name) { this.name = name; }

    @RelatedTo(type="MEMBER_OF", direction=Direction.OUTGOING, enforceTargetType=true)
    Dojo dojo;

    @RelatedTo(type="MEMBER_OF", direction=Direction.OUTGOING, enforceTargetType=true)
    MailingList mailingList;

    public void setDojo(Dojo dojo) {
        this.dojo = dojo;
    }
    public void setMailingList(MailingList mailingList) {
        this.mailingList = mailingList;
    }

    @Override
    public String toString() {
        return "Person [name=" + name + "]";
    }
}

With no other changes to the repository, this code runs without any errors, and inspecting the created Neo4j database shows that it is behaving as expected.

