Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Savepoints, Checkpoints, Rollbacks?

      excuse me if what I say doesn't make sense!

Isn't the save points a feature that should go into JTA rather than JPA, of course JPA should provide a facility to use the the save points provided by JTA.


On Tue, Feb 17, 2009 at 8:42 PM, James Sutherland <jamesssss@xxxxxxxxx> wrote:

There are no savepoints in JPA.  Please log this enhancement request in

The native EclipseLink API has something similar called nested UnitOfWork,
but these are entirely in-memory nested transactions.  Nested UnitOfWork
support has currently not been exposed in the EclipseLink JPA API.

With your code the main thing to be careful of is ensuring the consistency
of your object changes and database (the database will get rolled back, but
your objects will remain the same).  Clear will clear out all the objects,
so may be ok.  You also need to consider the shared cache, but by default a
flush() followed by a clear() will invalidate the changed objects, so should
be ok.

paulccarey wrote:
> OK so it doesn't look like this is possible directly with JPA or
> Eclipselink as far as I can tell however I've managed to coble this
> together, in case its of any use to anyone hear goes....
> first to get a savepoint...
> EntityManager em;
> ...
>     public Savepoint getSavepoint() throws SQLException {
>         em.flush();
>         //Get the SQL connection
>         Connection conn = ((UnitOfWorkImpl) ((JpaEntityManager)
> em).getActiveSession().acquireUnitOfWork()).getAccessor().getConnection();
>         //Get a savepoint from the SQL connection
>         return conn.setSavepoint();
>     }
> next to make use of it...
>     public void commitToSave1(Savepoint sp) throws SQLException {
>         Connection conn = ((UnitOfWorkImpl) ((JpaEntityManager)
> em).getActiveSession().acquireUnitOfWork()).getAccessor().getConnection();
>         //roll the connection back to the savepoint
>         conn.rollback(sp);
>         //commit the current state of the transaction
>         conn.commit();
>         //clear the persistence context causing all managed entities to
>         //become detached
>         em.clear();
>         //commit the transaction to release locks and reset the entity
>         //manager
>         em.getTransaction().commit();
>     }
> Hope that may be of use to someone:-D
> paulccarey wrote:
>> Hi I am using eclipselink with JPA
>> Is it possible to create savepoints like JDBC can?
>> So I can rollback a transaction to a certain point without losing all
>> changes?
>> Thanks
>> P

--- James Sutherland
 EclipseLink ,
Wiki: EclipseLink , TopLink
Forums: TopLink , EclipseLink
Book: Java Persistence
View this message in context:
Sent from the EclipseLink - Users mailing list archive at

eclipselink-users mailing list

Back to the top