Doing some tests I just stumbled over the following behaviour and wanted
to ask what I am doing wrong or whether that is a TopLink bug:
I am running the following sequence:
em.getTransaction().begin();
em.persist(new MyEntity("Test"));
em.getTransaction().commit();
The object correctly gets created in the database, I can see the text
"Test".
But inside of MyEntity, I am doing this:
@PostPersist
protected void afterInsert() {
this.anotherColumn = "Some other string";
}
And THAT ends up nowhere. I checked PostPersist using some tracing, it
really gets called. But any write attempts on the entity just are ingored.
So, is that wanted? If yes, what is the sense of @PostPersist if I
cannot modify my entity?
In my particular case, things are more complex: "Some other string" in
my real code is made up of a text template plus the autogenerated ID
(@GeneratedValue). Since @PostPersist is the only place where I can
obtain the autogenerated value, I do not see any workaround...
Thanks
Markus
--
http://www.xing.com/go/invita/58469