1 2 3 4 下一页 Hibernate 3.2支持JPA注解,Spring集成JPA是可选的。 下面是Spring集成JPA的一个例子。 实体类MyUser,使用JPA注解实现到数据库表myUser的映射,如下所示: package org.shirdrn.entity; import Java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Transient; @Entity public class MyUser { private Long id; private String userName; private String password; private String gender; private Integer age; private Integer birthYear; private String addr; private String email; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) public Long getId() { return id; } public void setId(Long id) { this.id = id; } @Column(name="userName") public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } @Column(name="password") public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Column(name="gender") public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } @Column(name="age") public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } @Column(name="addr") public String getAddr() { return addr; } public void setAddr(String addr) { this.addr = addr; } @Column(name="email") public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } @Transient public Integer getBirthYear() { return new Integer(2008-age); } public void setBirthYear(Integer age) { this.birthYear = new Integer(2008-age); } }
(责任编辑:admin) |