openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Georgi Naplatanov <>
Subject Re: How to detect whether there are any dirty objects?
Date Sat, 12 Apr 2008 11:29:00 GMT
Hello, David,

EntityTransaction.isActive() really don't do this. It's my mistake.

Because i'm interesting for this issue too, i make the following test,
but without success:

EntityManager em = emf.create EntityManager() ;
em.getTransaction.begin() ;
Query q = em.createQuery("DELETE FROM Myobject x") ;
q.executeUpdate() ;

OpenJPAEntityManager kem = OpenJPAPersistence.cast(em);

boolean isDirty = !(kem.getUpdatedClasses().isEmpty() &&
kem.getPersistedClasses().isEmpty() && kem.getRemovedClasses().isEmpty() ) ;

em.getTransaction().rollback() ;

But isDirty is always false. May be these methods do not work with queries.

Best regards

David Goodenough wrote:
> On Friday 11 April 2008, Georgi Naplatanov wrote:
>> Hello, David.
>> In your case EntityTransaction.isActive() should do the job.
>> Best regards
>> Georgi
>> David Goodenough wrote:
>>> Is there a way to detect whether there are any modified/dirty objects
>>> that need to be written to the datastore?  I do not need to know which
>>> objects are dirty, just whether there are any.
>>> I am trying to add the kind of functionality that puts up a question
>>> when someone tries to terminate the program without saving to
>>> point out that they need to save.
>>> Thanks,
>>> David
> The reference manual says that isActive tells me whether begin has been
> called more recently than commit or rollback (section 9.2).  Are you saying
> that if begin has been called but nothing has been modified that it will also
> return true.  Also if the last thing that was called was commit or rollback
> and begin has not yet been called will it be true if something has been 
> modified?
> David

View raw message