Quantcast
Channel: Spring Community Forums - NoSQL
Viewing all articles
Browse latest Browse all 128

findByXXX returns Map, not T

$
0
0
I'm using Spring Data Neo4J.

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

Code:

/**
 * 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.

Code:

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)

Code:

public interface UserRepository extends RelatedEntityRepository<UserNode>{
        public UserNode findByEntityId(Long id);
}

Here's a test:

Code:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"/graph-test-context.xml"})
@Transactional
public class UserRepositoryTests {

        @Autowired
        private UserRepository userRepository;
       
        // For Bug
        @Test
        public void canFindByEntityId()
        {
                UserNode userNode = new UserNode(1L);
                userRepository.save(userNode);
               
                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?

Viewing all articles
Browse latest Browse all 128

Trending Articles