nihao
package aa; import static javax.persistence.GenerationType.IDENTITY; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; import org.hibernate.annotations.Formula; /** * 注解必须是在属性上的,如果有任何一个注解在方法上,那么@Formula将失效 * @author 昆明蜂鸟软件 * @version 0.1.0 2008-7-15 下午06:09:38 */ @Entity @Table(name = "user", catalog = "test") public class User { @Id @GeneratedValue(strategy = IDENTITY) private int id; @Formula("(select COUNT(*) from user)") private int count; public int getId() { return id; } public void setId(int id) { this.id = id; } public int getCount() { return count; } public void setCount(int count) { this.count = count; } }