3
 g.V(apple).properties("name").drop();

This is how i try to delete the property of apple vertex, but getting an error

java.lang.IllegalStateException: Cannot access element because its enclosing transaction is closed and unbound

basically i'm trying to check that can we modify schema in TitanDB? i go through the documentation but didn't get anything thing about that.

Mayur Raikwar
  • 105
  • 1
  • 1
  • 9

2 Answers2

5

It could be that you didn't properly iterate your Traversal responsible for creating that vertex.

From the Gremlin Console, using Titan v1.0.0 and TinkerPop v3.0.1:

gremlin> graph = TitanFactory.open('conf/titan-cassandra-es.properties')
==>standardtitangraph[cassandrathrift:[127.0.0.1]]
gremlin> g = graph.traversal()
==>graphtraversalsource[standardtitangraph[cassandrathrift:[127.0.0.1]], standard]
gremlin> apple = g.addV().next()
==>v[4296]
gremlin> apple.property('name', 'Apple')
==>vp[name->Apple]
gremlin> apple.values()
==>Apple
gremlin> g.V(apple).properties('name').drop()
gremlin> apple.values()
gremlin>

Notice the call to .next() when creating the apple vertex.

jbmusso
  • 3,436
  • 1
  • 25
  • 36
1

The following example seems to work for me:

gremlin> produce = g.addVertex();
==>v[12]
gremlin> produce.values();
gremlin> produce.property("name", "apple");
==>vp[name->apple]
gremlin> produce.values();
apple
g.traversal().V(produce).properties("name").drop();
produce.values();

What are you doing before:

 g.V(apple).properties("name").drop();

The error you are getting

java.lang.IllegalStateException: Cannot access element because its enclosing transaction is closed and unbound

Is saying that the transaction is already closed which means that maybe you are committing or closing the graph. Either of those actions would close the transaction and make it unusable, so check your order of operations.

Filipe Teixeira
  • 3,565
  • 1
  • 25
  • 45
  • yeah i commit the transcation. – Mayur Raikwar Apr 14 '16 at 07:04
  • Committing always closes the transaction. Reopen your graph after committing and your property drop will work. – Filipe Teixeira Apr 14 '16 at 07:05
  • actually i'm using intellij and i didn't method addVertex method and though i find addV() method and also check i with gremlin console didn't work either – Mayur Raikwar Apr 14 '16 at 07:26
  • The example I produced is using `Titan-1` and `Tinkerpop-3` which has a very similar syntax in java. The premise is the same though. Commiting closes transactions, thus you need to reopen your graph. – Filipe Teixeira Apr 14 '16 at 07:30
  • gremlin> tx = graph.newTransaction(); ==>standardtitantx[0x4b325930] gremlin> produce = g.addVertex() Getting this error No signature of method: org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource.addVertex() is applicable for argument types: () values: [] – Mayur Raikwar Apr 14 '16 at 07:34
  • According to that error message your `g` is actually a `traversal` not a `graph` so you are incorrectly using `g`. I see that you created a new transaction with `tx = graph.newTransaction();` now you can just try `tx.addVertex()` that will work. – Filipe Teixeira Apr 14 '16 at 07:38
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/109118/discussion-between-mayur-raikwar-and-fido). – Mayur Raikwar Apr 14 '16 at 07:39
  • @Fido In the default Titan setup (see `scripts/empty-sample.groovy`), `g` is meant to be a `Traversal` and `graph` is meant to be a `Graph`. Also, `g = graph.traversal()` is expensive and should be a one-time operation at startup. – jbmusso Apr 14 '16 at 08:58