Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6820553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:26:18+00:00 2026-05-26T21:26:18+00:00

The problem that I’m running into is that after I make an AutoIndex index

  • 0

The problem that I’m running into is that after I make an AutoIndex index a certain property, I can add a key/value pair and the index won’t show that it’s there. I’m relatively new to neo4j so my concept of what this class is supposed to do might be wrong. The test code creates an impermanent graph database, instantiates my data service class with it, and then creates a user. When the data service class is instantiated, that’s when the properties are added to the AutoIndex. You can see inside the createUser() function, I’ve printed out the user that I’ve just created and should be in the AutoIndex, but it prints null.

This is the code I’m testing:

@Before
public void setup() throws IOException {
    graphDb = new ImpermanentGraphDatabase();
    Transaction tx = graphDb.beginTx();
    try {
        nA = graphDb.createNode();
        nB = graphDb.createNode();
        packetA = graphDb.createNode();
        packetB = graphDb.createNode();
        dataService = new DataServiceImpl(graphDb);
        tx.success();
    }
    finally
    {
        tx.finish();
    }
}

/****************** Test User Creation Functionality *******************/

@Test
public void createUser() throws ExistsException {
    Transaction tx = graphDb.beginTx();
    try {
        UserWrapper user = (UserWrapper) dataService.createUser(BigInteger.valueOf(1));
        tx.success();
    }
    finally {
        tx.finish();
    }
}

Here’s the code in DataServiceImpl:

/**
 * Node property keys that should be auto-indexed.
 */
private static final Set<String> NODE_KEYS_INDEXABLE = new HashSet<String>(
        Arrays.asList(new String[] { UserWrapper.KEY_IDENTIFIER }));

/**
 * Relationship property keys that should be auto-index.
 */
private static final Set<String> REL_KEYS_INDEXABLE = new HashSet<String>(
        Arrays.asList(new String[] { SentWrapper.TIME_PROP }));

private void initIndices() {
/* Get the auto-indexers */
AutoIndexer<Node> nodeAutoIndexer = this.graphDb.index()
        .getNodeAutoIndexer();

RelationshipAutoIndexer relAutoIndexer = this.graphDb.index()
        .getRelationshipAutoIndexer();

this.updateIndexProperties(nodeAutoIndexer,
        DataServiceImpl.NODE_KEYS_INDEXABLE);

this.nodeIndex = nodeAutoIndexer.getAutoIndex();

this.updateIndexProperties(relAutoIndexer,
        DataServiceImpl.REL_KEYS_INDEXABLE);

this.relIndex = relAutoIndexer.getAutoIndex();
}

/**
 * Sets the indexed properties of an {@link AutoIndexer} to the specified
 * set, removing old properties and adding new ones.
 * 
 * @param autoIndexer
 *            the AutoIndexer to update.
 * @param properties
 *            the properties to be indexed.
 * @return autoIndexer, this given AutoIndexer (useful for chaining calls.)
 */
private <T extends PropertyContainer> AutoIndexer<T> updateIndexProperties(
    AutoIndexer<T> autoIndexer, Set<String> properties) {
Set<String> indexedProps = autoIndexer.getAutoIndexedProperties();
// Remove unneeded properties.
for (String prop : difference(indexedProps, properties)) {
    autoIndexer.stopAutoIndexingProperty(prop);
}

// Add new properties.
for (String prop : difference(properties, indexedProps)) {
    autoIndexer.startAutoIndexingProperty(prop);
}

// Enable the index, if needed.
if (!autoIndexer.isEnabled()) {
    autoIndexer.setEnabled(true);
}

return autoIndexer;
}

public User createUser(BigInteger identifier) throws ExistsException {
    // Verify that user doesn't already exist.
    if (this.nodeIndex.get(UserWrapper.KEY_IDENTIFIER, identifier).getSingle() != null) {
        throw new ExistsException("User with identifier '" + identifier.toString() + "' already exists.");
    }
    // Create new user.
    final Node userNode = graphDb.createNode();
    final User user = new UserWrapper(userNode);
    user.setIdentifier(identifier);

    Node userNode2 = this.nodeIndex.get(UserWrapper.KEY_IDENTIFIER, identifier).getSingle();
    System.out.println(userNode2);

    userParent.getNode().createRelationshipTo(userNode, NodeRelationships.PARENT);

    return user;
}

Here’s the code in UserWrapper:

/**
* Mapping to neo4j key for the identifier property.
*/
//Changed to public in order to test in Test class 
static final String KEY_IDENTIFIER = "identifier";

@Override
public void setIdentifier(BigInteger newIdentity) {
    neo4jNode.setProperty(KEY_IDENTIFIER, newIdentity.toByteArray());
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:26:19+00:00Added an answer on May 26, 2026 at 9:26 pm

    Where do you add the second user? By running the test twice? Then ImpermanentGraphDatabase will have deleted all data (as it is intended for testing) before the second run. The indexing happens at commit time, and aggregates all changes during the transaction, that’s why you don’t see it within the tx (userNode2). If you’d like to you can add this check to the test (see below).

    From your code it is also not visible where you call the initIndices, could you please indicate the place? Please also verify that the auto-indexer is indexing the correct properties.

    Try to change your test to, then the second call should throw the exception:

    @Test(expected = ExistsException.class)
    public void createUser() throws ExistsException {
        Transaction tx = graphDb.beginTx();
        try {
            UserWrapper user = (UserWrapper) dataService.createUser(BigInteger.valueOf(1));
            tx.success();
        }
        finally {
            tx.finish();
        }
        Node userNode2 = this.graphDb.index().getNodeAutoIndexer().getAutoIndex().get(UserWrapper.KEY_IDENTIFIER, identifier).getSingle();
        assertNotNull(userNode2);
    
        Transaction tx = graphDb.beginTx();
        try {
            UserWrapper user = (UserWrapper) dataService.createUser(BigInteger.valueOf(1));
            tx.success();
        }
        finally {
            tx.finish();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Simple problem that I can't figure out... How can I print a '%' character
I have the problem that an specific step in Ant can only be executed
The problem that I am facing at the moment as can be seen in
The problem that i'm having is how can i synchronise my datasets in my
I am currently running into a problem where an element is coming back from
I have a French site that I want to parse, but am running into
One problem that I have frequently run into lately is the problem of my
STL containers have the problem that iterators can be invalidated when the container changes.
So I got a problem that I can't wrap my mind around. I'm creating
I have a problem that I believe I need to use grouping using xsl:key

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.