package com.pas.dao;
import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import com.pas.pojo.Test;
/**
* A data access object (DAO) providing persistence and search support for Test
* 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.pas.pojo.Test
* @author MyEclipse Persistence Tools
*/
@Repository
public class TestDAO extends HibernateDaoSupport {
private static final Logger log = LoggerFactory.getLogger(TestDAO.class);
// property constants
public static final String NAME = "name";
@Autowired
public void setSessionFactoryOverride(SessionFactory sessionFactory) {
super.setSessionFactory(sessionFactory);
}
protected void initDao() {
// do nothing
}
public void saveTest(Test transientInstance) {
log.debug("saving Test instance");
try {
Session session = super.getSessionFactory().getCurrentSession();
session.saveOrUpdate(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
throw new RuntimeException("自定义异常");//不提交测试代码
}
public void save(Test transientInstance) {
log.debug("saving Test instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Test persistentInstance) {
log.debug("deleting Test instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Test findById(java.lang.Integer id) {
log.debug("getting Test instance with id: " + id);
try {
Test instance = (Test) getHibernateTemplate().get(
"com.pas.pojo.Test", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List<Test> findByExample(Test instance) {
log.debug("finding Test instance by example");
try {
List<Test> results = (List<Test>) getHibernateTemplate()
.findByExample(instance);
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 Test instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Test as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public List<Test> findByName(Object name) {
return findByProperty(NAME, name);
}
public List findAll() {
log.debug("finding all Test instances");
try {
String queryString = "from Test";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public Test merge(Test detachedInstance) {
log.debug("merging Test instance");
try {
Test result = (Test) getHibernateTemplate().merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Test instance) {
log.debug("attaching dirty Test instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Test instance) {
log.debug("attaching clean Test instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static TestDAO getFromApplicationContext(ApplicationContext ctx) {
return (TestDAO) ctx.getBean("TestDAO");
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
SpringMVC3 + Hibernate4 例子代码
共90个文件
jar:59个
class:6个
java:6个
4星 · 超过85%的资源 需积分: 9 28 下载量 86 浏览量
2013-02-05
22:43:42
上传
评论
收藏 17.01MB RAR 举报
温馨提示
这是一个自己弄的SpringMVC3 + Hibernate4 例子代码,希望对你有用.
资源推荐
资源详情
资源评论
收起资源包目录
PASystem.rar (90个子文件)
PASystem
.springBeans 474B
.myhibernatedata 583B
.settings
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.common.project.facet.core.xml 252B
org.eclipse.wst.common.component 462B
org.eclipse.wst.jsdt.ui.superType.container 49B
.jsdtscope 500B
org.eclipse.jdt.core.prefs 364B
src
com
pas
dao
SubtestDAO.java 4KB
TestDAO.java 5KB
pojo
Subtest.java 1KB
Test.java 1KB
controller
TestController.java 445B
service
TestService.java 638B
.project 2KB
WebRoot
META-INF
MANIFEST.MF 36B
WEB-INF
web.xml 1KB
classes
com
pas
dao
SubtestDAO.class 6KB
TestDAO.class 6KB
pojo
Test.class 2KB
Subtest.class 2KB
controller
TestController.class 762B
service
TestService.class 1KB
lib
org.springframework.instrument.tomcat-3.1.1.RELEASE.jar 11KB
org.springframework.instrument-3.1.1.RELEASE.jar 7KB
jboss-transaction-api_1.1_spec-1.0.0.Final.jar 11KB
spring-security-core-3.1.0.RELEASE.jar 340KB
spring-security-acl-3.1.0.RELEASE.jar 79KB
dom4j-1.6.1.jar 307KB
spring-security-aspects-3.1.0.RELEASE.jar 6KB
org.springframework.web.struts-3.1.1.RELEASE.jar 31KB
commons-fileupload-1.2.jar 52KB
c3p0-0.9.1.2.jar 596KB
spring-security-remoting-3.1.0.RELEASE.jar 12KB
aspectjweaver-1.6.9.jar 1.59MB
org.springframework.beans-3.1.1.RELEASE.jar 576KB
org.springframework.orm-3.1.1.RELEASE.jar 370KB
commons-beanutils-1.7.0.jar 184KB
log4j-1.2.16.jar 470KB
aopalliance-1.0.jar 4KB
hibernate-entitymanager-4.1.4.Final.jar 466KB
antlr-2.7.7.jar 435KB
commons-pool-1.5.3.jar 94KB
org.springframework.context-3.1.1.RELEASE.jar 812KB
org.springframework.asm-3.1.1.RELEASE.jar 52KB
commons-httpclient-3.1.jar 298KB
spring-security-web-3.1.0.RELEASE.jar 250KB
org.springframework.aspects-3.1.1.RELEASE.jar 49KB
jboss-logging-3.1.0.GA.jar 59KB
httpclient-4.1.1.jar 343KB
slf4j-api-1.6.1.jar 25KB
commons-logging-1.1.1.jar 59KB
org.springframework.core-3.1.1.RELEASE.jar 439KB
mysql-connector-java-5.1.6-bin.jar 687KB
ehcache-1.6.2.jar 198KB
commons-dbcp-1.4.jar 157KB
org.springframework.jdbc-3.1.1.RELEASE.jar 395KB
spring-security-openid-3.1.0.RELEASE.jar 19KB
org.springframework.oxm-3.1.1.RELEASE.jar 71KB
org.springframework.context.support-3.1.1.RELEASE.jar 105KB
cglib-nodep-2.2.jar 315KB
org.springframework.expression-3.1.1.RELEASE.jar 172KB
cas-client-core-3.1.12.jar 84KB
spring-security-config-3.1.0.RELEASE.jar 198KB
hibernate-jpa-2.0-api-1.0.1.Final.jar 100KB
commons-collections-3.2.jar 558KB
org.springframework.transaction-3.1.1.RELEASE.jar 241KB
hibernate-core-4.1.4.Final.jar 4.21MB
spring-security-cas-3.1.0.RELEASE.jar 25KB
org.springframework.aop-3.1.1.RELEASE.jar 324KB
commons-lang-2.5.jar 273KB
spring-security-crypto-3.1.0.RELEASE.jar 40KB
spring-security-ldap-3.1.0.RELEASE.jar 91KB
hibernate-commons-annotations-4.0.1.Final.jar 79KB
org.springframework.web.portlet-3.1.1.RELEASE.jar 186KB
openid4java-nodeps-0.9.6.jar 214KB
spring-security-taglibs-3.1.0.RELEASE.jar 21KB
javassist-3.15.0-GA.jar 633KB
org.springframework.web-3.1.1.RELEASE.jar 532KB
guice-2.0.jar 651KB
org.springframework.jms-3.1.1.RELEASE.jar 195KB
org.springframework.web.servlet-3.1.1.RELEASE.jar 560KB
spring.tld 17KB
spring-form.tld 74KB
applicationContext.xml 2KB
PASystem-servlet.xml 1KB
pages
success.jsp 842B
index.jsp 834B
.mymetadata 297B
.classpath 6KB
.myeclipse
共 90 条
- 1
资源评论
- tritreechina2013-06-22挺好的例子,可惜不是连接实际数据库的例子。
- TaAnZuo2014-07-15资料还行,顺利掌握大概的用法,谢谢分享
- qq3618979862018-03-26可以用,感谢分享,谢谢
- nalalan2013-09-08适合初学者。
- lanyu352013-04-06我没办法运行啊
不净之心
- 粉丝: 49
- 资源: 49
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 论文(最终)_20240430235101.pdf
- 基于python编写的Keras深度学习框架开发,利用卷积神经网络CNN,快速识别图片并进行分类
- 最全空间计量实证方法(空间杜宾模型和检验以及结果解释文档).txt
- 5uonly.apk
- 蓝桥杯Python组的历年真题
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 前端开发技术实验报告:内含4四实验&实验报告
- Highlight Plus v20.0.1
- 林周瑜-论文.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功