Announcement Announcement Module
No announcement yet.
<T> findByXXX returns Map, not T Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • <T> findByXXX returns Map, not T

    I'm using Spring Data Neo4J.

    I have extended the basic GraphRepository interface, adding a method, as follows:

     * Extension to the repository interface for standard Spring Data repo's that
     * perform operations on graph entities that have a related RDBMS entity.
     * @author martypitt
     * @param <T>
    public interface RelatedEntityRepository<T> extends GraphRepository<T>, 
    RelationshipOperationsRepository<T>,CypherDslRepository<T>  {
    	public T findByEntityId(Long id);
    However, I'm finding that subclasses of this interface don't behave as expected.

    public interface UserRepository extends RelatedEntityRepository<UserNode>{
    When I call UserRepository.findByEntityId(), I expect to get a single instance of UserNode returned, or null.
    Instead, I get a scala.collection.JavaConversions$MapWrapper.

    However, if I change the UserRepository to specify the type, then everything works (though, defeats the purpose of the baseclass)

    public interface UserRepository extends RelatedEntityRepository<UserNode>{
    	public UserNode findByEntityId(Long id);
    Here's a test:

    public class UserRepositoryTests {
    	private UserRepository userRepository;
    	// For Bug
    	public void canFindByEntityId()
    		UserNode userNode = new UserNode(1L);;
    		UserNode node = userRepository.findByEntityId(1L);
    		assertThat(node, notNullValue());
    		assertThat(node, isA(UserNode.class));
    Running this test with the extra line in UserRepository commented out fails. Otherwsie, the test passes.

    Is this a bug? Have I written the repo interface correctly?

  • #2
    Which version do you use?