Keyword.java
//*******************************************************************//
//
//** 创建人: 何岳军
//
//** 描 述: message表(留言表)实体bean
//
//** 版 本: 湖南农业大学关工委网站2010版
//
//*******************************************************************//
package cn.hauggw.beans;
import java.util.*;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
@Entity
@Table(name="tb_keyword")
public class Keyword {
private long id; // 自动编号
private int uid; // 用户id
private String keyword; // 关键字
private int property; // 属性 0 1
private Date adddate; //日期
@Id
@GeneratedValue(generator = "paymentableGenerator")
@GenericGenerator(name = "paymentableGenerator", strategy = "identity")
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Column(name="uid")
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
@Column(name="keyword")
public String getKeyword() {
return keyword;
}
public void setKeyword(String keyword) {
this.keyword = keyword;
}
@Column(name="property")
public int getProperty() {
return property;
}
public void setProperty(int property) {
this.property = property;
}
@Column(name="adddate")
public Date getAdddate() {
return adddate;
}
public void setAdddate(Date adddate) {
this.adddate = adddate;
}
}
DAO.java (接口类)
//*******************************************************************//
//
//** 创建人: 何岳军
//
//** 描 述: DAO接口
//
//** 版 本: 湖南农业大学关工委网站2010版
//
//*******************************************************************//
package cn.hauggw.service;
public interface DAO {
/**
* 获取记录总数
* @param entityClass 实体类
* @return
*/
public <T> long getCount(Class<T> entityClass);
/**
* 清除一级缓存的数据
*/
public void clear();
/**
* 保存实体
* @param entity 实体id
*/
public void save(Object entity);
/**
* 更新实体
* @param entity 实体id
*/
public void update(Object entity);
/**
* 删除实体
* @param entityClass 实体类
* @param entityid 实体id
*/
public <T> void delete(Class<T> entityClass, Object entityid);
/**
* 删除实体
* @param entityClass 实体类
* @param entityids 实体id数组
*/
public <T> void delete(Class<T> entityClass, Object[] entityids);
/**
* 获取实体
* @param <T>
* @param entityClass 实体类
* @param entityId 实体id
* @return
*/
public <T> T find(Class<T> entityClass, Object entityId);
}
DAOService.java
//*******************************************************************//
//
//** 创建人: 何岳军
//
//** 描 述: DAO实现
//
//** 版 本: 湖南农业大学关工委网站2010版
//
//*******************************************************************//
package cn.hauggw.service.impl;
import java.io.Serializable;
import javax.annotation.Resource;
import org.hibernate.SessionFactory;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import cn.hauggw.service.DAO;;
@Transactional
public class DAOService implements DAO {
@Resource private SessionFactory sessionFactory;
public void clear() {
sessionFactory.getCurrentSession().clear();
}
public <T> void delete(Class<T> entityClass, Object entityid) {
delete(entityClass,new Object[]{entityid});
}
public <T> void delete(Class<T> entityClass, Object[] entityids) {
for(Object id : entityids){
sessionFactory.getCurrentSession().delete(sessionFactory.getCurrentSession().load(entityClass, (Serializable) id));
}
}
@SuppressWarnings("unchecked")
@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
public <T> T find(Class<T> entityClass, Object entityId) {
return (T) sessionFactory.getCurrentSession().get(entityClass, (Serializable) entityId);
}
@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
public <T> long getCount(Class<T> entityClass) {
return 0;
}
public void save(Object entity) {
sessionFactory.getCurrentSession().persist(entity);
}
public void update(Object entity) {
sessionFactory.getCurrentSession().merge(entity);
}
}
bean.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:annotation-config/>
<!-- <context:component-scan base-package="cn" /> -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>
<property name="url" value="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=ggwnet"/>
<property name="username" value="sa"/>
<property name="password" value="hyj_lk"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="annotatedClasses">
<list>
<!-- <value>classpath:/cn/hauggw/beans</value> -->
<value>cn.hauggw.beans.Message</value>
<value>cn.hauggw.beans.Keyword</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.SQLServerDialect
hibernate.show_sql=true
hibernate.format_sql=true
</value>
</property>
</bean>
<!-- 事务管理器 -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:annotation-driven transaction-manager="txManager"/>
<bean id="daoService" class="cn.hauggw.service.impl.DAOService" />
<bean id="keywordService" class="cn.hauggw.service.impl.KeywordServiceBean" />
</beans>
分享到:
相关推荐
SpringMVC Spring Hibernate 框架整合 Annotation Maven Project
Struts2 Spring Hibernate 框架整合 Annotation Maven project
Struts2 Spring Hibernate 框架整合 Annotation Maven project.zip
struts2 spring2.5 hibernate3.0 annotation 整合
使用spring和hibernate的Annotation的小项目,帮助新手理解annotation
Struts2+Spring2+Hibernate3+Annotation所需JAR包
JSF+Spring+Hibernate(Annotation)的login小实例,建议入门的朋友看看,老鸟就免了,呵呵。环境:SQLSever2000+jdk5.0+spring2.0+hibernate3.2+jsf
SpringMVC Spring MyBatis 框架整合 Annotation Maven Project
jquery easyUI+struts2+spring+hibernate基于annotation实现的CRM
马士兵视频里的struts2 hibernate3 spring2.5 annotation 整合 绝对好用 里面还有jar包 部署就可以用
该zip包含 hibernate3.3.2相关jar与文档,hibernate annotation3.3.4相关jar与文档。
struts2+spring2+hibernate3 Annotation整合例子
下载后请修改数据库用户名和密码,即springAnnotation-hibernate.xml文件 案例系统支持功能如下: 注册功能,身份证,邮箱,手机号,姓名等校验,ajax异步获取资源 分页显示,编辑更新,多行删除等更功能,使用了MVC...
hibernate annotation hibernate3
spring3、 hibernate4 配置声明式事务管理(annotation方式)
Struts1.3 + Hibernate3.3 + Spring3.0 Annotation整合
这里面包涵了需要用Hibernate Annotation时,所需要的所有jar包! 现在我们公司在做web项目的时候,已经不用*.hbm.xml这种映射文件了,都是用Annotation(注解)方式来完成实体与表之间的映射关系,这样看起来比用...
hibernate annotation spring 中文参考文档
spring加入hibernate annotation方式第一部分,需要其他部分请查看本人其他资源