An example of adding, deleting, modifying, and querying a small file written using the hibernate framework is as follows: it is a standard writing format; [java] package www.csdn.net. bookhome. daoimpl; import java. util. list; import org. hibernate. session; import org. hibernate. transaction; import www.csdn.net. bookhome. dao. adminDao; import www.csdn.net. bookhome. dao. baseHibernateDao; import www.csdn.net. bookhome. domain. admin; import www.csdn.net. bookhome. utils. hibernateSessionFactory; public class AdminDaoImpl extends BaseHibernateDao implements AdminDao {public void deleteObject (Admin entity) {Transaction tx = null; try {Session session = getSession (); tx = Session. beginTransaction (); session. delete (entity); tx. commit ();} catch (Exception e) {tx. rollback (); throw new RuntimeException ("delete all errors" + e);} finally {HibernateSessionFactory. closeSession () ;}} public void deleteObjectById (Integer id) {Transaction tx = null; try {Session session = getSession (); tx = session. beginTransaction (); session. save (id); tx. commit ();} catch (Exception e) {tx. rollback (); throw new RuntimeException ("Error Based on id" + e);} finally {HibernateSessionFactory. closeSession () ;}} public List getAllObjects (Class entityClass) {try {return getSession (). createQuery ("from Admin "). list ();} catch (Exception e) {throw new RuntimeException ("Search error" + e);} finally {HibernateSessionFactory. closeSession () ;}} public Admin getObjectById (Class className, Integer id) {try {return (Admin) getSession (). get (className, id);} catch (Exception e) {throw new RuntimeException ("error found by id" + e);} finally {HibernateSessionFactory. closeSession () ;}} public List getObjects (Class clazz, int from, int size, String orderName) {try {return getSession (). createQuery ("from Admin "). setFirstResult (from-1) * size ). setMaxResults (size ). list ();} catch (Exception e) {throw new RuntimeException ("Paging query error" + e);} finally {HibernateSessionFactory. closeSession () ;}} public Admin loadObjectById (Class className, Integer id) {try {return (Admin) getSession (). load (className, id);} catch (Exception e) {throw new RuntimeException ("load query error" + e);} finally {HibernateSessionFactory. closeSession () ;}} public void saveObject (Admin entity) {Transaction tx = null; try {Session session = getSession (); tx = session. beginTransaction (); session. save (entity); tx. commit ();} catch (Exception e) {tx. rollback (); throw new RuntimeException ("Save error" + e);} finally {HibernateSessionFactory. closeSession () ;}} public void updateObject (Admin entity) {Transaction tx = null; try {Session session = getSession (); tx = session. beginTransaction (); session. update (entity); tx. commit ();} catch (Exception e) {tx. rollback (); throw new RuntimeException ("Update error" + e);} finally {HibernateSessionFactory. closeSession () ;}} public Admin getAllObjects (String name) {try {return (Admin) getSession (). createQuery ("from Admin a where. adminName =: name "). setParameter ("name", name ). uniqueResult ();} catch (Exception e) {throw new RuntimeException ("error found by user query" + e);} finally {HibernateSessionFactory. closeSession () ;}} public Admin login (Admin entity) {try {return (Admin) getSession (). createQuery ("from Admin a where. adminName =: name and. adminPassword =: pass "). setString ("name", entity. getAdminName ()). setString ("pass", entity. getAdminPassword ()). uniqueResult ();} catch (Exception e) {throw new RuntimeException ("Logon error" + e);} finally {HibernateSessionFactory. closeSession ();}}}