I have a Spring MVC web-app, where this back-end has all RESTful web-services, so we have an entity.jar, a dao.jar, and services.jar, and web-services.war.
In the DAO layer, I've had this discussion with my boss before that when we save or update, we want to have an object returned that is managed and can have lazy-loading done on it.
We do have a Postgres SQL database and the primary key is a long, and is set by a sequence in Postgres.
So, I have the following two methods:
@Override
public MyEntity create(MyEntity myObject)
{
this.sessionFactory.getCurrentSession().save(myObject);
this.sessionFactory.getCurrentSession().flush();
this.sessionFactory.getCurrentSession().refresh(myObject);
return myObject;
}
@Override
public MyEntity update(MyEntity myObject)
{
this.sessionFactory.getCurrentSession().update(myObject);
this.sessionFactory.getCurrentSession().flush();
this.sessionFactory.getCurrentSession().refresh(myObject);
return myObject;
}
My boss is very technical, and has looked up these methods himself to see what they all do. He thinks we don't need the flush and refresh. But all my unit tests show these two methods have always worked well.
So, I ask you is there anything wrong with the way I am using these two methods? These would be called from any business services (services.jar). The business services are obviously where the transaction and session begin.
Thanks!