4

I'm working with OrientDB with Java API. I have this warning, and I don't understand why:

The command 'create vertex type 'Users' as subclass of 'V'' must be executed outside an active transaction: the transaction will be committed and reopen right after it. To avoid this behavior execute it outside a transaction

My Java code is:

OrientGraph graph = new OrientGraphFactory(databaseUrl).getTx();
graph.createVertexType(User.CLASS_NAME);
graph.createKeyIndex(User.MAIL_KEY, Vertex.class, new Parameter<>("type", "UNIQUE"),new Parameter<>("class", User.CLASS_NAME));
graph.commit();
graph.shutdown();
besil
  • 1,308
  • 1
  • 18
  • 29

1 Answers1

3

The solution is to use a transactionless connection to the database. Your first line should be:

OrientGraphNoTx graph = new OrientGraphFactory(databaseUrl).getNoTx();

The OrientGraphNoTx object supports the same methods for creating vertices, edges and types as OrientGraph. Note that the commands you issue towards this object will not be part of a transaction, and will be committed immediately (so you don't need the line where you commit. Still need to be closed though). I suggest you implement a way of creating the vertex and edge types you need during startup, so it doesn't interfere with normal operations.

Knut
  • 136
  • 9
  • That's exactly the case: I'd like to create types and indices in unit testing. So this operation is done once, at database start for the first time. Thank you! – besil Dec 25 '15 at 22:46