`
shiwj1010
  • 浏览: 97312 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

看同事用了hibernate anotation,也记录一下吧

    博客分类:
  • j2ee
阅读更多
一直用的xxx.hbm.xml, 看同事用这种方式也挺方便的,学习一下
import java.io.Serializable;
import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name="OBM_WORK_RESULT")
public class WorkResultEntity implements Serializable {

	@Id
	@Column(name="resultId", length=32)
	private String id;
	@Basic
	@Column(name="reportContentId", length=32 )
	private String reportContentId;
	@Basic
	@Column(name="quantity" )
	private int quantity;
	@Basic
	@Column(name="hour" )
	private int hour;
	@Basic
	@Column(name="issue" )
	private int issue;
	@Basic
	@Column(name="bug" )
	private int bug;
	@Basic
	@Column(name="createTime" )
	private Date createTime;
	@Basic
	@Column(name="updateTime" )
	private Date updateTime;
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getReportContentId() {
		return reportContentId;
	}
	public void setReportContentId(String reportContentId) {
		this.reportContentId = reportContentId;
	}
	public int getQuantity() {
		return quantity;
	}
	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}
	public int getHour() {
		return hour;
	}
	public void setHour(int hour) {
		this.hour = hour;
	}
	public int getIssue() {
		return issue;
	}
	public void setIssue(int issue) {
		this.issue = issue;
	}
	public int getBug() {
		return bug;
	}
	public void setBug(int bug) {
		this.bug = bug;
	}
	public Date getCreateTime() {
		return createTime;
	}
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	public Date getUpdateTime() {
		return updateTime;
	}
	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}
	
		
}


applicationContext.xml中sessionFactory要使用AnnotationSessionFactoryBean
	<bean id="mySessionFactory"
		class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
		<property name="dataSource">
			<ref bean="dataSource" />
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">
					org.hibernate.dialect.HSQLDialect
				</prop>
				<prop key="hibernate.show_sql">
					true
				</prop>
			</props>
		</property>
		<property name="annotatedClasses">
			<list>
		  		<value>org.chuck.data.model.entity.ProjectEntity</value>
		  		<value>org.chuck.data.model.entity.WorkContentEntity</value>
		  		<value>org.chuck.data.model.entity.WeeklyReportEntity</value>
		  		<value>org.chuck.data.model.entity.FunctionEntity</value>	  
		  		<value>org.chuck.data.model.entity.WorkResultEntity</value>
		  		<value>org.chuck.data.model.entity.ReportContentEntity</value>
		  		<value>org.chuck.data.model.entity.PersonEntity</value>	
			</list>
		</property>
	</bean>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics