当前位置: 代码迷 >> Eclipse >> myeclpise 自动生成的DAO类应该怎么使用
  详细解决方案

myeclpise 自动生成的DAO类应该怎么使用

热度:82   发布时间:2016-04-23 14:27:31.0
myeclpise 自动生成的DAO类应该如何使用啊
用myeclipse   hibernate3.1可以自动生成dao类,但是dao类的方法不是静态的,应该如何来调用这些方法呢?

代码如下

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;

/**
  *   Data   access   object   (DAO)   for   domain   model   class   ArtSpecialty.
  *  
  *   @see   edu.njut.art.hibernate.ArtSpecialty
  *   @author   MyEclipse   Persistence   Tools
  */

public   class   ArtSpecialtyDAO   extends   BaseHibernateDAO   {
private   static   final   Log   log   =   LogFactory.getLog(ArtSpecialtyDAO.class);


 
//   property   constants
public   static   final   String   SP_NAME   =   "spName ";

 
public   void   save(ArtSpecialty   transientInstance)   {
log.debug( "saving   ArtSpecialty   instance ");
try   {
getSession().save(transientInstance);
log.debug( "save   successful ");
}   catch   (RuntimeException   re)   {
log.error( "save   failed ",   re);
throw   re;
}
}

public   void   delete(ArtSpecialty   persistentInstance)   {
log.debug( "deleting   ArtSpecialty   instance ");
try   {
getSession().delete(persistentInstance);
log.debug( "delete   successful ");
}   catch   (RuntimeException   re)   {
log.error( "delete   failed ",   re);
throw   re;
}
}

public   ArtSpecialty   findById(java.lang.String   id)   {
log.debug( "getting   ArtSpecialty   instance   with   id:   "   +   id);
try   {
ArtSpecialty   instance   =   (ArtSpecialty)   getSession().get(
"edu.njut.art.hibernate.ArtSpecialty ",   id);
return   instance;
}   catch   (RuntimeException   re)   {
log.error( "get   failed ",   re);
throw   re;
}
}

public   List   findByExample(ArtSpecialty   instance)   {
log.debug( "finding   ArtSpecialty   instance   by   example ");
try   {
List   results   =   getSession().createCriteria(
"edu.njut.art.hibernate.ArtSpecialty ").add(
Example.create(instance)).list();
log.debug( "find   by   example   successful,   result   size:   "
+   results.size());
return   results;
}   catch   (RuntimeException   re)   {
log.error( "find   by   example   failed ",   re);
throw   re;
}
}

public   List   findByProperty(String   propertyName,   Object   value)   {
log.debug( "finding   ArtSpecialty   instance   with   property:   "
+   propertyName   +   ",   value:   "   +   value);
try   {
String   queryString   =   "from   ArtSpecialty   as   model   where   model. "