我在配置映射的时候遇到的问题,就是user_id是sqlserver的关键字无法使用,然后数据库是原先的不能修改字段名。如何用注解的方式定义id以及其他字段对应表的字段名(如“[user_id]”),我在user_id 下加入@column会报错不能这样做吗? package zttc.itat.model; import java.util.Date; 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.validator.constraints.Email; import org.hibernate.validator.constraints.NotEmpty; @Entity @Table(name="[user]") public class User { private Integer user_id; private String user_name; private String face; private String pass; private String true_name; private String mobile; private String tel; private String email; private boolean enable; private Date time; private Date login_time; private Date last_login_time; @GeneratedValue(strategy=GenerationType.IDENTITY) @Id public Integer getId() { return user_id; } public void setId(Integer id) { this.user_id = id; } @NotEmpty(message="用户名不能为空") public String getUsername() { return user_name; } public void setUsername(String username) { this.user_name = username; } @NotEmpty(message="用户密码不能为空") public String getPassword() { return pass; } public void setPassword(String password) { this.pass = password; } @Email(message="用户邮件格式不正确") public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public Integer getUser_id() { return user_id; } public void setUser_id(Integer user_id) { this.user_id = user_id; } public String getUser_name() { return user_name; } public void setUser_name(String user_name) { this.user_name = user_name; } public String getFace() { return face; } public void setFace(String face) { this.face = face; } public String getPass() { return pass; } public void setPass(String pass) { this.pass = pass; } public String getTrue_name() { return true_name; } public void setTrue_name(String true_name) { this.true_name = true_name; } public String getMobile() { return mobile; } public void setMobile(String mobile) { this.mobile = mobile; } public String getTel() { return tel; } public void setTel(String tel) { this.tel = tel; } public boolean isEnable() { return enable; } public void setEnable(boolean enable) { this.enable = enable; } public Date getTime() { return time; } public void setTime(Date time) { this.time = time; } } |
|
10分 |
在set方法上面使用@name注解,好像是这个,你查一下文档嘛
|
10分 |
@Column(name = “user_id”) |
20分 |
@column(user=”XXX”)
自己定义一个新名字 |