正好在写代码。
import javax.persistence.*;
/**
* 用户.
*
* 使用JPA annotation定义ORM关系.
* 使用Hibernate annotation定义二级缓存.
*
* @author neosu
*/
@Entity
//表名与类名不相同时重新定义表名.
@Table(name = "USERS")
//默认的缓存策略.
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class User {
private Long id;
private String loginName;
private String password; //为简化演示,使用明文保存密码.
private String name;
private String email;
private Set<Role> roles = new LinkedHashSet<Role>(); //有序的关联对象集合.
@Id
@SequenceGenerator(name="USERS_ID",sequenceName="USERS_ID",allocationSize=1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="USERS_ID")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
SpringSide 3.1.2的主键id序列值如何生成
最新推荐文章于 2024-08-25 21:18:14 发布