Hibernate中Entity实体类的写法
记录下一个Entity类的写法,方便以后查阅:
1 package com.bupt.auth.entity; 2 3 import java.util.Date; 4 5 import javax.persistence.Column; 6 import javax.persistence.Entity; 7 import javax.persistence.GeneratedValue; 8 import javax.persistence.GenerationType; 9 import javax.persistence.Id; 10 import javax.persistence.JoinColumn; 11 import javax.persistence.JoinTable; 12 import javax.persistence.ManyToOne; 13 import javax.persistence.Table; 14 15 @Entity 16 @Table(name="token") 17 public class Token { 18 @Id 19 @GeneratedValue(strategy=GenerationType.IDENTITY) 20 @Column(name="id", unique=true, nullable=false) 21 private Long id; 22 23 @Column(name="info") 24 private String info; 25 26 @Column(name="starttime") 27 private Date starttime; 28 29 @Column(name="endtime") 30 private Date endtime; 31 32 @ManyToOne(targetEntity=User.class) 33 @JoinTable(name="userToken", 34 joinColumns=@JoinColumn(name="token_id",referencedColumnName="id",unique=true), 35 inverseJoinColumns=@JoinColumn(name="user_id",referencedColumnName="id")) 36 private User user; 37 38 public Long getId() { 39 return id; 40 } 41 public void setId(Long id) { 42 this.id = id; 43 } 44 public String getInfo() { 45 return info; 46 } 47 public void setInfo(String info) { 48 this.info = info; 49 } 50 public Date getStarttime() { 51 return starttime; 52 } 53 public void setStarttime(Date starttime) { 54 this.starttime = starttime; 55 } 56 public Date getEndtime() { 57 return endtime; 58 } 59 public void setEndtime(Date endtime) { 60 this.endtime = endtime; 61 } 62 public User getUser() { 63 return user; 64 } 65 public void setUser(User user) { 66 this.user = user; 67 } 68 69 }