Hibernate映射的Entity实体类封装案例

曾经终败给现在 2022-01-28 05:31 348阅读 0赞
  1. /**
  2. * <p>
  3. * Title:User.java
  4. */
  5. package cn.surveystore.smk.entity;
  6. import java.io.Serializable;
  7. import java.sql.Timestamp;
  8. import java.util.Date;
  9. import java.util.Set;
  10. import javax.persistence.CascadeType;
  11. import javax.persistence.Column;
  12. import javax.persistence.Entity;
  13. import javax.persistence.FetchType;
  14. import javax.persistence.GeneratedValue;
  15. import javax.persistence.Id;
  16. import javax.persistence.JoinColumn;
  17. import javax.persistence.JoinTable;
  18. import javax.persistence.ManyToMany;
  19. import javax.persistence.Table;
  20. import javax.persistence.Transient;
  21. import org.hibernate.annotations.ForeignKey;
  22. import org.hibernate.annotations.GenericGenerator;
  23. import org.hibernate.annotations.Index;
  24. import cn.surveystore.common.constant.Constant;
  25. @Entity
  26. //表明该类是一个与数据表对应的实体类
  27. @Table(name = "user")
  28. //要映射的数据库表名,要与哪个数据库表建立映射关系
  29. public class User implements Serializable {
  30. private static final long serialVersionUID = 3329289113562169434L;
  31. private final static String tablefix = "u_";
  32. @Id
  33. //表名此字段在数据表中为主键
  34. @GeneratedValue(generator = "uuid")
  35. @GenericGenerator(name = "uuid", strategy = "uuid")
  36. @Column(name = "id", columnDefinition = "varchar(32) comment '会员唯一标示'")
  37. //实体类属性与数据表字段建立起联系,并说明字段类型和备注
  38. private String id;
  39. @Column(name = tablefix + "password")
  40. private String password;
  41. @Column(name = tablefix + "salt")
  42. private String salt;
  43. // @NotBlank(message = "邮箱不能为空")
  44. // @Pattern(regexp =
  45. // "\\w[-\\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\\.)+[A-Za-z]{2,14}", message =
  46. // "邮箱格式不正确")
  47. @Index(name = Constant.INDEXFIX + "EMAIL")
  48. @Column(name = tablefix + "email", unique = true)
  49. private String email;
  50. @Index(name = Constant.INDEXFIX + "USERNAME")
  51. @Column(name = tablefix + "user_name", unique = true)
  52. private String userName;
  53. // @NotBlank(message = "手机号码不能为空")
  54. // @Pattern(regexp =
  55. // "(13\\d|14[57]|15[^4,\\D]|17[678]|18\\d)\\d{8}|170[059]\\d{7}", message =
  56. // "手机号码格式有误")
  57. @Index(name = Constant.INDEXFIX + "PHONE")
  58. @Column(name = tablefix + "phone", unique = true)
  59. private String phone = "";
  60. /**
  61. * 激活状态
  62. */
  63. @Column(name = tablefix
  64. + "active", columnDefinition = "tinyint(1) not null default '0' comment '账号激活状态{0:未激活1:手机号激活2:邮箱激活3:全部激活}'")
  65. private Integer active = 0;
  66. /**
  67. * 激活字符串
  68. */
  69. @Column(name = tablefix + "active_id", columnDefinition = "char(32) not null default '0' comment '账号激活字符串'")
  70. private String activeId = "0";
  71. @Column(name = tablefix + "province")
  72. private String province = "";
  73. @Column(name = tablefix + "city")
  74. private String city = "";
  75. @Column(name = tablefix + "district")
  76. private String district = "";
  77. @Column(name = tablefix + "gender")
  78. private Integer gender = 1;
  79. @Column(name = tablefix + "birthday")
  80. private Date birthday;
  81. @Column(name = tablefix + "real_name")
  82. private String realName = "";
  83. @Column(name = tablefix + "company")
  84. private String company = "";
  85. @Column(name = tablefix + "from")
  86. private String from = "xyz";
  87. @Column(name = tablefix + "fromid")
  88. private String fromId = "0";
  89. @Column(name = tablefix + "alipay_num")
  90. private String alipayNum;
  91. @Column(name = tablefix + "check_phone_num")
  92. private Integer checkPhoneNum = 0;
  93. @Column(name = tablefix + "status")
  94. private Integer status = 1;
  95. @Column(name = tablefix + "type")
  96. private Integer type = 0;
  97. @Column(name = tablefix
  98. + "publish", columnDefinition = "tinyint(1) not null default 0 comment '神秘客是否公开{0:公开,1:私有}'")
  99. private Integer publish = 0;
  100. @Column(name = tablefix + "create_time")
  101. private Timestamp createTime;
  102. @Column(name = tablefix + "head_picture_address", columnDefinition = "varchar(255) default '' comment '头像地址'")
  103. private String headPictureAddress = "";
  104. /**
  105. * 账号密码(明码)
  106. */
  107. @Column(name = tablefix + "password_plain", columnDefinition = "varchar(32) default '0' comment'账号密码(明码)'")
  108. private String passwordPlain = "0";
  109. @ManyToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
  110. @JoinTable(name = Constant.TABLEFIX + "user_customer", joinColumns = {
  111. @JoinColumn(name = "uc_uid") }, inverseJoinColumns = { @JoinColumn(name = "uc_cid") })
  112. @ForeignKey(name = "null")
  113. private Set<Customer> customerSet;
  114. @ManyToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
  115. @JoinTable(name = Constant.TABLEFIX + "user_role", joinColumns = {
  116. @JoinColumn(name = "u_uid") }, inverseJoinColumns = { @JoinColumn(name = "r_rid") })
  117. @ForeignKey(name = "null")
  118. private Set<Role> roles;
  119. @ManyToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
  120. @JoinTable(name = Constant.TABLEFIX + "user_customer_level", joinColumns = {
  121. @JoinColumn(name = "ucl_uid") }, inverseJoinColumns = { @JoinColumn(name = "ucl_clid") })
  122. @ForeignKey(name = "null")
  123. private Set<CustomerLevel> customerLevelSet;
  124. @Transient
  125. private String loginName;
  126. /**
  127. * 账号是否需要限制单点登录
  128. */
  129. @Column(name = "is_sso", columnDefinition = "tinyint(3) not null default '0' comment '账号是否需要限制单点登录{0:不需要1:需要}'")
  130. private Integer isSso = 0;
  131. // 微信openid
  132. @Column(name = tablefix + "wx_openid", columnDefinition = "char(50) comment '微信openid'")
  133. private String wxOpenId;
  134. /**
  135. * 用户拓展信息
  136. */
  137. @Transient
  138. private UserInfo userInfo;
  139. /**
  140. * @return the id
  141. */
  142. public String getId() {
  143. return id;
  144. }
  145. /**
  146. * @param id the id to set
  147. */
  148. public void setId(String id) {
  149. this.id = id;
  150. }
  151. /**
  152. * @return the password
  153. */
  154. public String getPassword() {
  155. return password;
  156. }
  157. /**
  158. * @param password the password to set
  159. */
  160. public void setPassword(String password) {
  161. this.password = password;
  162. }
  163. /**
  164. * @return the salt
  165. */
  166. public String getSalt() {
  167. return salt;
  168. }
  169. /**
  170. * @param salt the salt to set
  171. */
  172. public void setSalt(String salt) {
  173. this.salt = salt;
  174. }
  175. /**
  176. * @return the email
  177. */
  178. public String getEmail() {
  179. return email;
  180. }
  181. /**
  182. * @param email the email to set
  183. */
  184. public void setEmail(String email) {
  185. this.email = email;
  186. }
  187. /**
  188. * @return the phone
  189. */
  190. public String getPhone() {
  191. return phone;
  192. }
  193. /**
  194. * @param phone the phone to set
  195. */
  196. public void setPhone(String phone) {
  197. this.phone = phone;
  198. }
  199. /**
  200. * @return the active
  201. */
  202. public Integer getActive() {
  203. return active;
  204. }
  205. /**
  206. * @param active the active to set
  207. */
  208. public void setActive(Integer active) {
  209. this.active = active;
  210. }
  211. /**
  212. * @return the activeId
  213. */
  214. public String getActiveId() {
  215. return activeId;
  216. }
  217. /**
  218. * @param activeId the activeId to set
  219. */
  220. public void setActiveId(String activeId) {
  221. this.activeId = activeId;
  222. }
  223. /**
  224. * @return the province
  225. */
  226. public String getProvince() {
  227. return province;
  228. }
  229. /**
  230. * @param province the province to set
  231. */
  232. public void setProvince(String province) {
  233. this.province = province;
  234. }
  235. /**
  236. * @return the city
  237. */
  238. public String getCity() {
  239. return city;
  240. }
  241. /**
  242. * @param city the city to set
  243. */
  244. public void setCity(String city) {
  245. this.city = city;
  246. }
  247. /**
  248. * @return the district
  249. */
  250. public String getDistrict() {
  251. return district;
  252. }
  253. /**
  254. * @param district the district to set
  255. */
  256. public void setDistrict(String district) {
  257. this.district = district;
  258. }
  259. /**
  260. * @return the gender
  261. */
  262. public Integer getGender() {
  263. return gender;
  264. }
  265. /**
  266. * @param gender the gender to set
  267. */
  268. public void setGender(Integer gender) {
  269. this.gender = gender;
  270. }
  271. /**
  272. * @return the birthday
  273. */
  274. public Date getBirthday() {
  275. return birthday;
  276. }
  277. /**
  278. * @param birthday the birthday to set
  279. */
  280. public void setBirthday(Date birthday) {
  281. this.birthday = birthday;
  282. }
  283. /**
  284. * @return the realName
  285. */
  286. public String getRealName() {
  287. return realName;
  288. }
  289. /**
  290. * @param realName the realName to set
  291. */
  292. public void setRealName(String realName) {
  293. this.realName = realName;
  294. }
  295. /**
  296. * @return the company
  297. */
  298. public String getCompany() {
  299. return company;
  300. }
  301. /**
  302. * @param company the company to set
  303. */
  304. public void setCompany(String company) {
  305. this.company = company;
  306. }
  307. /**
  308. * @return the from
  309. */
  310. public String getFrom() {
  311. return from;
  312. }
  313. /**
  314. * @param from the from to set
  315. */
  316. public void setFrom(String from) {
  317. this.from = from;
  318. }
  319. /**
  320. * @return the fromId
  321. */
  322. public String getFromId() {
  323. return fromId;
  324. }
  325. /**
  326. * @param fromId the fromId to set
  327. */
  328. public void setFromId(String fromId) {
  329. this.fromId = fromId;
  330. }
  331. /**
  332. * @return the alipayNum
  333. */
  334. public String getAlipayNum() {
  335. return alipayNum;
  336. }
  337. /**
  338. * @param alipayNum the alipayNum to set
  339. */
  340. public void setAlipayNum(String alipayNum) {
  341. this.alipayNum = alipayNum;
  342. }
  343. /**
  344. * @return the chackPhoneNum
  345. */
  346. public Integer getCheckPhoneNum() {
  347. return checkPhoneNum;
  348. }
  349. /**
  350. * @param chackPhoneNum the chackPhoneNum to set
  351. */
  352. public void setCheckPhoneNum(Integer checkPhoneNum) {
  353. this.checkPhoneNum = checkPhoneNum;
  354. }
  355. /**
  356. * @return the status
  357. */
  358. public Integer getStatus() {
  359. return status;
  360. }
  361. /**
  362. * @param status the status to set
  363. */
  364. public void setStatus(Integer status) {
  365. this.status = status;
  366. }
  367. /**
  368. * @return the type
  369. */
  370. public Integer getType() {
  371. return type;
  372. }
  373. /**
  374. * @param type the type to set
  375. */
  376. public void setType(Integer type) {
  377. this.type = type;
  378. }
  379. /**
  380. * @return the publish
  381. */
  382. public Integer getPublish() {
  383. return publish;
  384. }
  385. /**
  386. * @param publish the publish to set
  387. */
  388. public void setPublish(Integer publish) {
  389. this.publish = publish;
  390. }
  391. /**
  392. * @return the createTime
  393. */
  394. public Timestamp getCreateTime() {
  395. return createTime;
  396. }
  397. /**
  398. * @param createTime the createTime to set
  399. */
  400. public void setCreateTime(Timestamp createTime) {
  401. this.createTime = createTime;
  402. }
  403. /**
  404. * @return the customerSet
  405. */
  406. public Set<Customer> getCustomerSet() {
  407. return customerSet;
  408. }
  409. /**
  410. * @param customerSet the customerSet to set
  411. */
  412. public void setCustomerSet(Set<Customer> customerSet) {
  413. this.customerSet = customerSet;
  414. }
  415. /**
  416. * @return the roles
  417. */
  418. public Set<Role> getRoles() {
  419. return roles;
  420. }
  421. /**
  422. * @param roles the roles to set
  423. */
  424. public void setRoles(Set<Role> roles) {
  425. this.roles = roles;
  426. }
  427. /**
  428. * @return the customerLevelSet
  429. */
  430. public Set<CustomerLevel> getCustomerLevelSet() {
  431. return customerLevelSet;
  432. }
  433. /**
  434. * @param customerLevelSet the customerLevelSet to set
  435. */
  436. public void setCustomerLevelSet(Set<CustomerLevel> customerLevelSet) {
  437. this.customerLevelSet = customerLevelSet;
  438. }
  439. /**
  440. * @return the loginName
  441. */
  442. public String getLoginName() {
  443. return loginName;
  444. }
  445. /**
  446. * @param loginName the loginName to set
  447. */
  448. public void setLoginName(String loginName) {
  449. this.loginName = loginName;
  450. }
  451. public String getPasswordPlain() {
  452. return passwordPlain;
  453. }
  454. public void setPasswordPlain(String passwordPlain) {
  455. this.passwordPlain = passwordPlain;
  456. }
  457. public String getUserName() {
  458. return userName;
  459. }
  460. public void setUserName(String userName) {
  461. this.userName = userName;
  462. }
  463. /**
  464. * @return the headPictureAddress
  465. */
  466. public String getHeadPictureAddress() {
  467. return headPictureAddress;
  468. }
  469. /**
  470. * @param headPictureAddress the headPictureAddress to set
  471. */
  472. public void setHeadPictureAddress(String headPictureAddress) {
  473. this.headPictureAddress = headPictureAddress;
  474. }
  475. public Integer getIsSso() {
  476. return isSso;
  477. }
  478. public void setIsSso(Integer isSso) {
  479. this.isSso = isSso;
  480. }
  481. /**
  482. * @return the userInfo
  483. */
  484. public UserInfo getUserInfo() {
  485. return userInfo;
  486. }
  487. /**
  488. * @param userInfo the userInfo to set
  489. */
  490. public void setUserInfo(UserInfo userInfo) {
  491. this.userInfo = userInfo;
  492. }
  493. /**
  494. * @return the wxOpenId
  495. */
  496. public String getWxOpenId() {
  497. return wxOpenId;
  498. }
  499. /**
  500. * @param wxOpenId the wxOpenId to set
  501. */
  502. public void setWxOpenId(String wxOpenId) {
  503. this.wxOpenId = wxOpenId;
  504. }
  505. public User(String id, String password, String salt, String email, String userName, String phone, Integer active,
  506. String activeId, String province, String city, String district, Integer gender, Date birthday,
  507. String realName, String company, String from, String fromId, String alipayNum, Integer checkPhoneNum,
  508. Integer status, Integer type, Integer publish, Timestamp createTime, String passwordPlain,
  509. Set<Customer> customerSet, Set<Role> roles, Set<CustomerLevel> customerLevelSet, String loginName,
  510. String headPictureAddress, Integer isSso, UserInfo userInfo, String wxOpenId) {
  511. super();
  512. this.id = id;
  513. this.password = password;
  514. this.salt = salt;
  515. this.email = email;
  516. this.userName = userName;
  517. this.phone = phone;
  518. this.active = active;
  519. this.activeId = activeId;
  520. this.province = province;
  521. this.city = city;
  522. this.district = district;
  523. this.gender = gender;
  524. this.birthday = birthday;
  525. this.realName = realName;
  526. this.company = company;
  527. this.from = from;
  528. this.fromId = fromId;
  529. this.alipayNum = alipayNum;
  530. this.checkPhoneNum = checkPhoneNum;
  531. this.status = status;
  532. this.type = type;
  533. this.publish = publish;
  534. this.createTime = createTime;
  535. this.passwordPlain = passwordPlain;
  536. this.customerSet = customerSet;
  537. this.roles = roles;
  538. this.customerLevelSet = customerLevelSet;
  539. this.loginName = loginName;
  540. this.headPictureAddress = headPictureAddress;
  541. this.isSso = isSso;
  542. this.userInfo = userInfo;
  543. this.wxOpenId = wxOpenId;
  544. }
  545. public User() {
  546. super();
  547. }
  548. }

发表评论

表情:
评论列表 (有 0 条评论,348人围观)

还没有评论,来说两句吧...

相关阅读