Hi, new to Spring and here @stackoverflow
I'm building an stand-alone Inventory & Sales tracking app (Apache Pivot/Spring/JPA/Hibernate/MySQL) for a distributor business.
So far I think everything is CRUD, so I plan to have a base class with everything @Transactional.
Then I got a problem with my save generic method. Does persist and merge method of the EntityManager from Spring have a difference?
I tried running and called the save for both inserting and updating and it worked fine(I think spring automatically refreshes the entity every time I call my save method // saw the hibernate queries being logged, is this right?).
@Transactional
public abstract class GenericDAO {
protected EntityManager em;
// em getter+@PersistenceContext/setter
public void save(T t) {
// if (t.getId() == null) // create new
// {
// em.persist(t);
// } else // update
// {
em.merge(t);
// }
}
}
And btw, having a setup like this, I won't be much compromising performance right? Like calling salesDAO.findAll() for generating reports ( which does not need to be transactional, right? ).
thanks!!!