hibernate annotation注解方式来处理映射关系.docVIP

  • 1
  • 0
  • 约9.89千字
  • 约 13页
  • 2016-08-01 发布于河南
  • 举报

hibernate annotation注解方式来处理映射关系.doc

hibernate annotation注解方式来处理映射关系

在hibernate中,通常配置对象关系映射关系有两种,一种是基于xml的方式,另一种是基于annotation的注解方式,熟话说,萝卜青菜,可有所爱,每个人都有自己喜欢的配置方式,我在试了这两种方式以后,发现使用annotation的方式可以更简介,所以这里就简单记录下通过annotation来配置各种映射关系,在hibernate4以后已经将annotation的jar包集成进来了,如果使用hibernate3的版本就需要引入annotation的jar包。 一、单对象操作 @Entity  ---  如果我们当前这个bean要设置成实体对象,就需要加上Entity这个注解 @Table(name=t_user)  ----  设置数据库的表名 public class User { private int id; private String username; private String password; private Date born; private Date registerDate; @Column(name=register_date)  ---  Column中的name属性对应了数据库的该字段名字,里面还有其他属性,例如length,nullable等等 public Date getReg

文档评论(0)

1亿VIP精品文档

相关文档