hibernate生成的默认的属性值

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;
	}

	
	
}


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值