Results 1 to 2 of 2

Thread: [Neo4j] @Indexed not creating an index

  1. #1
    Join Date
    Oct 2012
    Posts
    1

    Default [Neo4j] @Indexed not creating an index

    Hi, i am having a problem with the @Indexed annotation. It only creates the index if i specify an indexname, otherwise it is not created

    I have the following entity:

    Code:
    @NodeEntity
    public class User {
    
    	@GraphId
    	private Long id;
    
    	@Indexed(unique = true)
    	private String username;
    }
    And i am testing the creation of the index with the following junit:

    Code:
    @Test
    public void shallAutomaticlyCreateIndexes() {
    		Index<PropertyContainer> usernameIndex = template.getIndex("username",
    				User.class);
    
    		Assert.assertNotNull(usernameIndex);
    	}
    And is failing the test unless i put something like this (the test is not failing because of the index name, it is directly not being created, i verified this with the neo4j server):

    Code:
    @NodeEntity
    public class User {
    
    	@GraphId
    	private Long id;
    
    	@Indexed(indexName = "username", unique = true)
    	private String username;
    }
    Apart from the above problem, i am having an odd behaviour with the following test when the indexName is not specified in the @Indexed annotation.

    Code:
    @Test
    public void shallGetByIndexedProperty() {
    		User user = new User(USERNAME);
    		user = userRepository.save(user);
    		Iterable<User> usersDb = userRepository.findAllByPropertyValue(
    				"username", USERNAME);
    		Assert.assertTrue(Iterables.size(usersDb) == 1);
    	}
    The above test is passing, although no lucene index is being created for the field (as verified in the previous JUnit), and if i did not get it wrong, only indexed fields can be searched for.

    I am using
    Code:
    <neo4j.version>1.8.RC1</neo4j.version>
    <spring-data-neo4j.version>2.1.0.BUILD-SNAPSHOT</spring-data-neo4j.version>
    Any thoughts?

  2. #2
    Join Date
    Jan 2011
    Location
    Dresden, Germany
    Posts
    525

    Default

    Hi,

    for the first unit-test did you set up your neo4j-config and repositories? The indexes in neo4j are usually created lazily (i.e. when something is added to them). If you set up the repository support though they are added due to the metadata listener facilities of the MappingContext (this creates both named indexes and index-names defaulting to the short classname).

    for #2 - if there was no index created (did you check afterwards?) the test wouldn't pass.

    Are you aware that the spring testing infrastructure rolls-back tests with @Transactional annotations (that includes index creation). Perhaps that's the reason for your issue?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •