Vertex is not creating

49 views
Skip to first unread message

manish kumar

unread,
Jul 16, 2016, 1:17:32 PM7/16/16
to Aurelius
I have this code in my web application

            TitanTransaction newTransaction = graph.newTransaction();
            TitanVertex newUser = graph.addVertex(GraphConstants.VertexLabel.user.toString());
            newUser.property(UserGraphConstants.VertexProps.accessToke.toString(), "123");
            newUser.property(UserGraphConstants.VertexProps.gender.toString(), userData.getGender());
            newUser.property(UserGraphConstants.VertexProps.joinedDate.toString(), System.currentTimeMillis());
            newUser.property(UserGraphConstants.VertexProps.userBlocked.toString(), false);
            newUser.property(UserGraphConstants.VertexProps.userLoginId.toString(), userData.getEmail());
            newUser.property(UserGraphConstants.VertexProps.userName.toString(), userData.getName());
            newUser.property(UserGraphConstants.VertexProps.userPwd.toString(), passwordEncoder.encode(userData.getPwd()));
            newTransaction.commit();

            HashMap returnValues = new HashMap();
            returnValues.put("name", userData.getName());
            returnValues.put("id", newUser.id());

Here returnValues.put("id", newUser.id()); return new vertex id.
But when i do 

        TitanGraph graph = TitanFactory.open("/home/manish/do_practice/titan/titan-1.0.0-hadoop1/conf/titan-cassandra-es.properties");
        TitanVertex v = graph.query().has(UserGraphConstants.VertexProps.userLoginId.toString(), "f...@xyz.com").vertices().iterator().next();
        System.out.println(v);

In my desktop application I am getting java.util.NoSuchElementException.

What may be the reason?

Jason Plurad

unread,
Jul 16, 2016, 5:02:48 PM7/16/16
to Aurelius
hi manish,

The reason is that you added the vertex on a transaction that wasn't committed. Your code created a thread-independent transaction, but the vertex was created on the auto-started Titan transaction.

Given the code above, this should be sufficient:

TitanVertex newUser = graph.addVertex(GraphConstants.VertexLabel.user.toString());
//...
graph
.tx().commit();

Or if you really want to go with an explicit transaction, use the transaction object to create the vertex:

TitanTransaction newTransaction = graph.newTransaction();
TitanVertex newUser = newTransaction.addVertex(GraphConstants.VertexLabel.user.toString());
//...
newTransaction
.commit();


http://tinkerpop.incubator.apache.org/docs/3.0.1-incubating/#transactions

http://s3.thinkaurelius.com/docs/titan/1.0.0/tx.html

-- Jason

manish kumar

unread,
Jul 24, 2016, 6:55:04 AM7/24/16
to Aurelius
I am still facing this problem. I have a tomcat server and i do

        TitanGraph graph = TitanFactory.open("/home/manish/do_practice/titan/titan-1.0.0-hadoop1/conf/titan-cassandra-es.properties");

this just on app start. use the same "graph" instance throughout my application.

After i add any vertex or edge i call graph.tx().commit()

But I see some edge are not available untill i restart my app.

manish kumar

unread,
Jul 25, 2016, 11:11:40 AM7/25/16
to Aurelius
From my very old question 


I found that graph.rollback() must be done before any read operation. does that apply for Titan1.0 also?

Kevin Schmidt

unread,
Jul 25, 2016, 11:27:31 AM7/25/16
to Aurelius
From the TinkerPop 3 docs, it appears it would be the case: http://tinkerpop.apache.org/docs/current/reference/#transactions

manish kumar

unread,
Jul 25, 2016, 11:37:23 AM7/25/16
to Aurelius
But in the given link i only see that rollback() is to undo the changes ?

Stephen Mallette

unread,
Jul 25, 2016, 12:34:53 PM7/25/16
to Aurelius
For web applications that work in a stateless request/response fashion you have to be sure that transactions don't leak among threads. The use of rollback() at the start of a request is a safety net to ensure that you don't have that problem. Of course, that could mask a problem with a leak so it does not really excuse you from having sound transactional semantics in your web app. 

On Mon, Jul 25, 2016 at 11:37 AM, manish kumar <mkj.o...@gmail.com> wrote:
But in the given link i only see that rollback() is to undo the changes ?

--
You received this message because you are subscribed to the Google Groups "Aurelius" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aureliusgraph...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/aureliusgraphs/b166ce93-534f-4677-8ee7-013535a158dc%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

manish kumar

unread,
Jul 25, 2016, 12:43:50 PM7/25/16
to Aurelius
Of course, that could mask a problem with a leak so it does not really excuse you from having sound transactional semantics in your web app. 
Can you elaborate this bit more 

Kevin Schmidt

unread,
Jul 25, 2016, 12:44:17 PM7/25/16
to aureliu...@googlegroups.com
The rollback just ensures that anything done in a prior request does not cause a stale transaction to be used.  If you already commit or rollback at the end of every request, the additional rollback at the start of the next should not be required.

On Mon, Jul 25, 2016 at 8:37 AM, manish kumar <mkj.o...@gmail.com> wrote:
But in the given link i only see that rollback() is to undo the changes ?

--
You received this message because you are subscribed to the Google Groups "Aurelius" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aureliusgraph...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages