Several methods in the generation of Hibernate DAO under Eclipse

Source: Internet
Author: User

A few days ago, using Eclipse generated hibernate DAO to do a small example of the implementation of additions and deletions, here to explain how to generate a DAO in the end what is the use of some methods.
Here I will explain this in the following Java code as an annotation.
Package DAO;
/** */ /**
* Simple introduction of the bag you want to use
*/
Import java.util.List;
Import Org.apache.commons.logging.Log;
Import Org.apache.commons.logging.LogFactory;
Import Org.hibernate.LockMode;
Import Org.hibernate.Query;
Import Org.hibernate.criterion.Example;

/** */ /**
* Class Usertabledao inherited the Basehibernatedao
*/
public class Usertabledao extends Basehibernatedao ... {

private static Final log = Logfactory.getlog (Usertabledao.class);

public static final String name = "Name";

Public-static final String age = ' age ';
/** *//**
* The Save () method provides the ability to add data to the database, but can only be added, this DAO does not generate update () method
* But you can simply eight Save () method renamed with Update function: Will GetSession (). Save
* (transientinstance) The sentence is changed into
* GetSession (). Merge (Transientinstance) or getsession (). saveorupdate
* (transientinstance);
*/
public void Save (usertable transientinstance) ... {
Log.debug ("Saving usertable instance");
Try ... {
GetSession (). Save (Transientinstance);
Log.debug ("Save Successful");
catch (RuntimeException re) ... {
Log.error ("Save Failed", re);
throw re;
}
}
/** *//**
* Delete () method is used to delete the name of the known meaning.
*/
public void Delete (Usertable persistentinstance) ... {
Log.debug ("deleting usertable instance");
Try ... {
GetSession (). Delete (persistentinstance);
Log.debug ("delete successful");
catch (RuntimeException re) ... {
Log.error ("Delete failed", re);
throw re;
}
}
/** *//**
* The FindByID () method implements querying data by ID.
*/
Public usertable FindByID (Java.lang.Integer ID) ... {
Log.debug ("Getting usertable instance with ID:" + ID);
Try ... {
usertable instance = (usertable) getsession (). Get ("DAO. Usertable ",
ID);
return instance;
catch (RuntimeException re) ... {
Log.error ("Get Failed", re);
throw re;
}
}

Related Article

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.