理论上有这两种方法:
1.那我保存记录时,转化数据类型。但是该怎么转化?2.或者是手工改配置文件里的String为Blob??行得通吗?希望各位多提建议,当然详细一点更好。
最后,请分析一下这两种方法的优缺点,可以从各个方面考虑,如占用存储空间大小,存储效率等。
1.那我保存记录时,转化数据类型。但是该怎么转化?2.或者是手工改配置文件里的String为Blob??行得通吗?希望各位多提建议,当然详细一点更好。
最后,请分析一下这两种方法的优缺点,可以从各个方面考虑,如占用存储空间大小,存储效率等。
import java.util.List;
import java.util.Set;
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;/**
* A data access object (DAO) providing persistence and search support for
* Examinee entities. Transaction control of the save(), update() and delete()
* operations can directly support Spring container-managed transactions or they
* can be augmented to handle user-managed Spring transactions. Each of these
* methods provides additional information for how to configure it for the
* desired type of transaction control.
*
* @see com.hepeng.events.Examinee
* @author MyEclipse Persistence Tools
*/public class ExamineeDAO extends BaseHibernateDAO {
private static final Log log = LogFactory.getLog(ExamineeDAO.class);
// property constants
public static final String IDENTITY_CARD_ID = "identityCardId";
public static final String CERTIFICATE_ID = "certificateId";
public static final String NAME = "name";
public static final String DEPARTMENT = "department";
public static final String SEX = "sex";
public static final String AGE = "age";
public static final String PHOTO = "photo"; public void save(Examinee transientInstance) {
log.debug("saving Examinee instance");
try {
getSession().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
} public void delete(Examinee persistentInstance) {
log.debug("deleting Examinee instance");
try {
getSession().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
} public Examinee findById(java.lang.Integer id) {
log.debug("getting Examinee instance with id: " + id);
try {
Examinee instance = (Examinee) getSession().get(
"com.hepeng.events.Examinee", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
} public List findByExample(Examinee instance) {
log.debug("finding Examinee instance by example");
try {
List results = getSession().createCriteria(
"com.hepeng.events.Examinee").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 Examinee instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Examinee as model where model."
+ propertyName + "= ?";
Query queryObject = getSession().createQuery(queryString);
queryObject.setParameter(0, value);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
} public List findByIdentityCardId(Object identityCardId) {
return findByProperty(IDENTITY_CARD_ID, identityCardId);
} public List findByCertificateId(Object certificateId) {
return findByProperty(CERTIFICATE_ID, certificateId);
} public List findByName(Object name) {
return findByProperty(NAME, name);
} public List findByDepartment(Object department) {
return findByProperty(DEPARTMENT, department);
} public List findBySex(Object sex) {
return findByProperty(SEX, sex);
} public List findByAge(Object age) {
return findByProperty(AGE, age);
} //其实没有这个需求
public List findByPhoto(Object photo) {
return findByProperty(PHOTO, photo);
} public List findAll() {
log.debug("finding all Examinee instances");
try {
String queryString = "from Examinee";
Query queryObject = getSession().createQuery(queryString);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
} public Examinee merge(Examinee detachedInstance) {
log.debug("merging Examinee instance");
try {
Examinee result = (Examinee) getSession().merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
} public void attachDirty(Examinee instance) {
log.debug("attaching dirty Examinee instance");
try {
getSession().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
} public void attachClean(Examinee instance) {
log.debug("attaching clean Examinee instance");
try {
getSession().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
}
结贴啦!