I have a simple relationship (Account)-[IdentifiedBy]->(Identity), defined like this
@RelatedTo(type = "IDENTIFIED_BY", direction = Direction.OUTGOING)
private Set<Identity> identities = new HashSet<Identity>();
When I load the Account and access its identities, all the identities are loaded, but all their properties except for ID are null. However, if I annotate the property with @Fetch, then the identities are loaded correctly, with all properties. Is this by design or am I missing something?
@NodeEntity
public class Account {
@GraphId Long nodeId;
@RelatedTo(type = "IDENTIFIED_BY", direction = Direction.OUTGOING)
//@Fetch
private Set<Identity> identities = new HashSet<Identity>();
public Set<Identity> getIdentities() {
return identities;
}
public void setIdentities(Set<Identity> identities) {
this.identities = identities;
}
}
@NodeEntity
public class Identity {
@GraphId Long nodeId;
private String identifier;
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
}
public interface AccountRepository extends GraphRepository<Account> { }
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"/test-context.xml"})
@Transactional
public class AccountTests {
@Autowired
protected AccountRepository accountRepository;
@Test
public void accountMustLoadItsIdentities() {
Account acct = accountRepository.save(new Account());
Identity id = new Identity();
id.setIdentifier("merlin");
acct.getIdentities().add(id);
accountRepository.save(acct);
acct = accountRepository.findOne(acct.nodeId);
id = acct.getIdentities().iterator().next();
assertEquals("merlin", id.getIdentifier());
}
}
The unit test fails on the last assertion, but succeeds if @Fetch on Account is uncommented.