package com.wls.hibernate.bean;
import java.util.Date;
import java.util.StringTokenizer;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.Formula;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;
@Entity
//@Immutable
@Table(name="TB_USERS")
//@org.hibernate.annotations.DynamicUpdate
public class User {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
private String firstName;
private String lastName;
private Integer age;
private String email;
@Generated(GenerationTime.INSERT)//hibernate默认值设置
@Column(columnDefinition=" INT default 1 ")
private float sex;
@Formula("(select avg(t.age) from TB_USERS t)")//formula属性测试
private String avgAge;
@Column(updatable=false,insertable=false)//数据库生成值测试
@Generated(GenerationTime.INSERT)
private Date modified;
public String getName() {
return firstName+" "+lastName;
}
public void setName(String name) {
StringTokenizer tokenizer=new StringTokenizer(name);
firstName=tokenizer.nextToken();
lastName=tokenizer.nextToken();
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getAvgAge() {
return avgAge;
}
public void setAvgAge(String avgAge) {
this.avgAge = avgAge;
}
}