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;
}
}