Guice-Persist and EclipseLink - saveOrUpdate

182 views
Skip to first unread message

Carlos Alexandro Becker

unread,
May 10, 2012, 4:00:04 PM5/10/12
to google...@googlegroups.com
I used to use Hibernate almost all my life. Now I'm trying JPA2 with EclipseLink, but, I don't know how to write a GenericDao.

I simply don't know how to write a saveOrUpdate like method.

my current code are just like this:

@Transactional
      public B save(B bean) {
        if (bean == null || bean.getId() == null) {
            persist(bean);
        } else {
            bean = update(bean);
        }
        return bean;
      }     

      protected final B update(B bean) {
        bean = em().merge(bean);
        em().flush();
        return bean;
      }

It almost work. The only problem is that it dont update the @Version of the entities.

Whats wrong?

PS: em() return basically my injected Provider<EntityManager>.get().

Thanks in advance.
Reply all
Reply to author
Forward
0 new messages