Quantcast
Channel: Spring+JPA+Hibernate: persist is updating the entity surprisingly. Please go through the details - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Spring+JPA+Hibernate: persist is updating the entity surprisingly. Please go through the details

$
0
0

In my code, I did as follows:

  • queried for a course entity
  • populate it with the given course data.
  • courseDao.update(entity) which internally calls persist(entity) method.
  • Surprisingly, the data is got updated successfully.

I am confused with this behaviour of persist method.

Please help me out.

code is as below:

//My Service......@Service("myService")@Transactionalpublic class MyServiceImpl implements MyService {  @Transactional(rollbackFor = { Throwable.class })  public void updateCourse(final Course course) throws MyServiceException {    ------    ------    CourseEntity courseEntity = courseDao.findById(course.getId());    populateCourseEntity(courseEntity, course);    courseDao.update(courseEntity);  }}//CourseDao.....public class CourseDaoImpl implements CourseDao {   --------   public void update(final T entity) throws MyDaoException {        if (entity != null) {            this.entityManager.persist(entity);        }        else {            String errMsg = "Object to be updated cannot be null.";            throw new MyDaoException(errMsg);        }    }}

Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images