HibernateDaoSupport makes adding, deleting, modifying, and querying simple.

Source: Internet
Author: User

Since Hibernate integrates JDBC, the code used by Hibernate to connect to and access the database is much less than that used to access the database directly. However, the Code for accessing the Hibernate configuration file, SessionFactory, and Session must be added accordingly. In order to solve the reuse problem of the same code above, Hibernate again encapsulated it, so we were lucky to see HibernateDaoSupport. Therefore, it is easier to use the HibernateDaoSupport template for database access, especially for simple addition, deletion, modification, and query. The following is my own code reference:/*** @ author wifygoo * simple addition, deletion, modification, and query of enterprise information. */Public class EnterpriseDaoImpl extends HibernateDaoSupport implements EnterpriseDao {/*** @ param Enterprise * deletes an Enterprise information. */Public void del (Enterprise enterprise) {this. getHibernateTemplate (). delete (enterprise) ;}/ *** @ return all Enterprise information. * Query all enterprise information. * // @ SuppressWarnings ("unchecked") public List <Enterprise> findallpolicises () {String hql = "from Enterprise enterprise"; return this. getHibernateTemplate (). find (hql);}/*** @ param Integer, enterprise ID. * @ Return refers to the information of an enterprise. * Query enterprise information by enterprise ID. */Public Enterprise findEnterpriseById (Integer id) {return (Enterprise) this. getHibernateTemplate (). load (Enterprise. class, id);}/*** @ param Enterprise * to add Enterprise information. */Public void save (Enterprise enterprise) {this. getHibernateTemplate (). save (enterprise);}/*** @ param Enterprise * modify Enterprise information. */Public void update (Enterprise enterprise) {this. getHibernateTemplate (). update (enterprise );}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.