Suggested Pages

Tuesday, May 22, 2012

Hibernate vs JPA: Modifying persistent objects

In this post i will show how to modify a persisted object using hibernate and jpa language:

Hibernate

sess is the hibernate Session object. In this snippet code, the dog entity becomes a managed entity so changes to this object will be performed on the DB.
   
  Dog dog = (Dog) sess.load( Dog.class, new Long(20) );
  dog.setName("Sean");
  sess.flush(); 




JPA

em is the EntityManager object. In this snippet code, the dog entity becomes a managed entity so changes to this object will be performed on the DB.
   
  Dog dog = (Dog) em.find( Dog.class, new Long(20) );
  dog.setName("Sean");
  em.flush();  

No comments :

Post a Comment

Suggested Pages