openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christopher Cudennec" <Smutje...@gmx.net>
Subject Auditing: Tests and maps
Date Tue, 06 Dec 2011 15:40:56 GMT
Hi OpenJPA team, hi Pinaki!

I've finally managed to check out the new auditing facility of OpenJPA 2.2 and have some feedback
for you guys:

1) No test possible for tracking updates?

I first tried to reuse my Junit tests for auditing and wondered why your new implementation
did not work. The explanation seems to be that I don't get the "audit" event for updates if
my Junit test rolls back the transaction. I saw that the TransactionEventManager does not
fire the #beforeCommit in that case. Do you have an idea how I could re-write my tests?

2) Still problems with Maps

I did not do a broad implementation of the auditor but instantly tried out the problem that
I already got with maps (see my older posts). Unfortunately the problem is still there. This
is my scenario:

@Entity
class A {
  @ElementCollection(fetch = FetchType.EAGER)
  private Map<String, StringAttribute> stringAttributes = new HashMap<String, StringAttribute>();
}

@Embeddable
class StringAttribute extends AbstractAttribute<String> {
  private String value;
}

class AuditTest {
  
  @Test
  public void test() {
    // create the object
    A a = new A();
	a.getStringAttributes().put("key", new StringAttribute("value"));
	em.persist(a);
	
	em.clear();
	
	// modify the object
	a = em.find(A.class, a.getId());
	a.getStringAttributes().get("key").setValue("new value"));
	em.flush();
  }
}

I try to explain what I do and what happens: When changing a value of a StringAttribute from
"A#stringAttributes" my auditor gets a notification. Unfortunately the Maps of the original
and the managed object contain the same values, i.e. the same instance of StringAttribute
that already has the new value. That's why I can't track the old value of the StringAttribute.

Do you have any idea if there is a problem with my implementation or with the auditor?

Thanks a lot,

Christopher
-- 
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!		
Jetzt informieren: http://www.gmx.net/de/go/freephone

Mime
View raw message