Am 26.08.2015 12:32 nachm. schrieb "ellirael" <[email protected]>:
>
> Looking through page at http://aries.apache.org/modules/jpaproject.html
and
> samples at
>
https://svn.apache.org/repos/asf/aries/trunk/jpa/examples/tasklist-blueprint/src/main/java/org/apache/aries/jpa/example/tasklist/blueprint/impl/
> I understand that I should use EmSupplier if I want thread safe
application.
You can also inject EntityManager. Aries jpa makes sure the access is
thread safe. The difference is that EmSupplier does not use a dynamic
proxy internally. So it is easier to debug.
>
> But I cannot understand some rows in the example.
>
> @Transaction
> @Override
> public void addTask(Task task) {
> em.get().persist(task);
> em.get().flush();
> }
> Does @Transaction annotation do or mean something? How is it merged with
> <tx> tag in blueprint config?
I think in this state of the code the annotation did not yet work. Using
transaction blueprint 1.1.1 the annotation should work. In the upcoming
release transaction 3.0 transactions are controlled exclusively via jta 1.2
@Transactional.
> Shouldn't I get EntityManager once in a method and use it?
> EntityManage em = emSupplier.get();
> em.persist(task);
> em.flush();
>
As you like.
>
> @Override
> public void deleteTask(Integer id) {
> em.get().remove(getTask(id));
> }
> Why we delete newly queried object from database instead of object that
> client views? There can be changes from other clients in database and we
> delete the same object but not the same object state.
> I'd like to be sure that I delete that I viewed.
The issue is that the entity would be detached. So the code would need to
cope with that too. You can implement it like this of course.
>
> public void setEm(EmSupplier em) {
> this.em = em;
> }
> Is there any need in this setter method?! I thought there is field
> injection.
I think I only use the setter for unit tests.
Christian
>
>
>
> --
> View this message in context:
http://karaf.922171.n3.nabble.com/Aries-JPA-EmSupplier-understanding-tp4042066.html
> Sent from the Karaf - User mailing list archive at Nabble.com.