google-code-export / objectify-appengine

Automatically exported from code.google.com/p/objectify-appengine
MIT License
1 stars 0 forks source link

Issue in Transactions : getting NPE #214

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I want to store an entity both in datastore and cloudsql in the transaction and 
either both ops get performed or none.
This is my code

Object transact = ofy.transact(new Work<Object>() {

            @Override
            public Object run() {
                Transaction transaction = ofy.getTransaction();
                ofy.save().entity(userSessionEntry).now();
                Connection sqlConnection = null;
                try {
                    sqlConnection = connectSql.connectToSql();
                } catch (ClassNotFoundException | SQLException e1) {
                    if (transaction != null && transaction.isActive()){
                        transaction.rollback();
                    }
                    return e1;
                });

I want like if i got into any exception my transaction get Rolled back.
But at Transaction transaction = ofy.getTransaction();
here transaction is giving NPE.

Can you please provide me required help.

I'm using Objectify 4.

Original issue reported on code.google.com by saurabh....@mediaagility.com on 10 Jul 2014 at 4:47

GoogleCodeExporter commented 9 years ago
Please ask on the Objectify google group - the issue tracker is not a place for 
support requests.

You should be using the static ofy() method on ObjectifyService.

Original comment by lhori...@gmail.com on 10 Jul 2014 at 2:59