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.