Guest User

Untitled

a guest
Aug 3rd, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.12 KB | None | 0 0
  1. How to fetch only desired property of bean in hibernate?
  2. public class User {
  3. // login info
  4. private long id;
  5. private String type;
  6.  
  7. private String userName;
  8. private String password;
  9. private String securityQuestionStr;
  10. private String securityAnswer;
  11.  
  12. // personal info
  13. private String firstName;
  14. private String middleName;
  15. private String lastName;
  16.  
  17. /**
  18. * <b>{@link GenderType} gender</b>
  19. */
  20. private GenderType gender;
  21.  
  22. private Date dateOfBirth;
  23.  
  24. // other related info
  25. /**
  26. * <b>{@link UserType} userType</b>
  27. */
  28. private UserType userType;
  29.  
  30. // contact info
  31. private Long mobileNo;
  32. private Long businessPhoneNo;
  33. private Long homePhoneNo;
  34. private Long faxNo;
  35. private String email;
  36. private String alternateEmail;
  37.  
  38. /**
  39. * <b>{@link RegistrationStatus} userStatus</b>
  40. */
  41. private RegistrationStatus userStatus;
  42.  
  43. /**
  44. * <b>{@link Post} posts</b>
  45. */
  46. private String securityAnswerHash;
  47. private String passwordHash;
  48. private String encryptedPassword;
  49. private String encryptedSecurityAnswer;
  50. private String nationality;
  51.  
  52. private String portal;
  53. private float version;
  54. private Date createdDate;
  55. private User createdUser;
  56. private String createdIP;
  57. private Date lastModifiedDate;
  58. private User lastModifiedUser;
  59. private String lastModifiedIP;
  60. private boolean recordStatus;
  61. private String publicKey;
  62. private String certificateName;
  63. private String signPublicKey;
  64. private String signCertificateName;
  65. private boolean isEtoken;
  66.  
  67. public long getId() {
  68. return id;
  69. }
  70. public void setId(long id) {
  71. this.id = id;
  72. }
  73. public String getType() {
  74. return type;
  75. }
  76. public void setType(String type) {
  77. this.type = type;
  78. }
  79. public String getUserName() {
  80. return userName;
  81. }
  82. public void setUserName(String userName) {
  83. this.userName = userName;
  84. }
  85. public String getPassword() {
  86. return password;
  87. }
  88. public void setPassword(String password) {
  89. this.password = password;
  90. }
  91. public String getSecurityQuestionStr() {
  92. return securityQuestionStr;
  93. }
  94. public void setSecurityQuestionStr(String securityQuestionStr) {
  95. this.securityQuestionStr = securityQuestionStr;
  96. }
  97. public String getSecurityAnswer() {
  98. return securityAnswer;
  99. }
  100. public void setSecurityAnswer(String securityAnswer) {
  101. this.securityAnswer = securityAnswer;
  102. }
  103. public String getFirstName() {
  104. return firstName;
  105. }
  106. public void setFirstName(String firstName) {
  107. this.firstName = firstName;
  108. }
  109. public String getMiddleName() {
  110. return middleName;
  111. }
  112. public void setMiddleName(String middleName) {
  113. this.middleName = middleName;
  114. }
  115. public String getLastName() {
  116. return lastName;
  117. }
  118. public void setLastName(String lastName) {
  119. this.lastName = lastName;
  120. }
  121. public GenderType getGender() {
  122. return gender;
  123. }
  124. public void setGender(GenderType gender) {
  125. this.gender = gender;
  126. }
  127. public Date getDateOfBirth() {
  128. return dateOfBirth;
  129. }
  130. public void setDateOfBirth(Date dateOfBirth) {
  131. this.dateOfBirth = dateOfBirth;
  132. }
  133. public UserType getUserType() {
  134. return userType;
  135. }
  136. public void setUserType(UserType userType) {
  137. this.userType = userType;
  138. }
  139. public Long getMobileNo() {
  140. return mobileNo;
  141. }
  142. public void setMobileNo(Long mobileNo) {
  143. this.mobileNo = mobileNo;
  144. }
  145. public Long getBusinessPhoneNo() {
  146. return businessPhoneNo;
  147. }
  148. public void setBusinessPhoneNo(Long businessPhoneNo) {
  149. this.businessPhoneNo = businessPhoneNo;
  150. }
  151. public Long getHomePhoneNo() {
  152. return homePhoneNo;
  153. }
  154. public void setHomePhoneNo(Long homePhoneNo) {
  155. this.homePhoneNo = homePhoneNo;
  156. }
  157. public Long getFaxNo() {
  158. return faxNo;
  159. }
  160. public void setFaxNo(Long faxNo) {
  161. this.faxNo = faxNo;
  162. }
  163. public String getEmail() {
  164. return email;
  165. }
  166. public void setEmail(String email) {
  167. this.email = email;
  168. }
  169. public String getAlternateEmail() {
  170. return alternateEmail;
  171. }
  172. public void setAlternateEmail(String alternateEmail) {
  173. this.alternateEmail = alternateEmail;
  174. }
  175. public RegistrationStatus getUserStatus() {
  176. return userStatus;
  177. }
  178. public void setUserStatus(RegistrationStatus userStatus) {
  179. this.userStatus = userStatus;
  180. }
  181. public String getSecurityAnswerHash() {
  182. return securityAnswerHash;
  183. }
  184. public void setSecurityAnswerHash(String securityAnswerHash) {
  185. this.securityAnswerHash = securityAnswerHash;
  186. }
  187. public String getPasswordHash() {
  188. return passwordHash;
  189. }
  190. public void setPasswordHash(String passwordHash) {
  191. this.passwordHash = passwordHash;
  192. }
  193. public String getEncryptedPassword() {
  194. return encryptedPassword;
  195. }
  196. public void setEncryptedPassword(String encryptedPassword) {
  197. this.encryptedPassword = encryptedPassword;
  198. }
  199. public String getEncryptedSecurityAnswer() {
  200. return encryptedSecurityAnswer;
  201. }
  202. public void setEncryptedSecurityAnswer(String encryptedSecurityAnswer) {
  203. this.encryptedSecurityAnswer = encryptedSecurityAnswer;
  204. }
  205. public String getNationality() {
  206. return nationality;
  207. }
  208. public void setNationality(String nationality) {
  209. this.nationality = nationality;
  210. }
  211. public String getPortal() {
  212. return portal;
  213. }
  214. public void setPortal(String portal) {
  215. this.portal = portal;
  216. }
  217. public float getVersion() {
  218. return version;
  219. }
  220. public void setVersion(float version) {
  221. this.version = version;
  222. }
  223. public Date getCreatedDate() {
  224. return createdDate;
  225. }
  226. public void setCreatedDate(Date createdDate) {
  227. this.createdDate = createdDate;
  228. }
  229. public User getCreatedUser() {
  230. return createdUser;
  231. }
  232. public void setCreatedUser(User createdUser) {
  233. this.createdUser = createdUser;
  234. }
  235. public String getCreatedIP() {
  236. return createdIP;
  237. }
  238. public void setCreatedIP(String createdIP) {
  239. this.createdIP = createdIP;
  240. }
  241. public Date getLastModifiedDate() {
  242. return lastModifiedDate;
  243. }
  244. public void setLastModifiedDate(Date lastModifiedDate) {
  245. this.lastModifiedDate = lastModifiedDate;
  246. }
  247. public User getLastModifiedUser() {
  248. return lastModifiedUser;
  249. }
  250. public void setLastModifiedUser(User lastModifiedUser) {
  251. this.lastModifiedUser = lastModifiedUser;
  252. }
  253. public String getLastModifiedIP() {
  254. return lastModifiedIP;
  255. }
  256. public void setLastModifiedIP(String lastModifiedIP) {
  257. this.lastModifiedIP = lastModifiedIP;
  258. }
  259. public boolean isRecordStatus() {
  260. return recordStatus;
  261. }
  262. public void setRecordStatus(boolean recordStatus) {
  263. this.recordStatus = recordStatus;
  264. }
  265. public String getPublicKey() {
  266. return publicKey;
  267. }
  268. public void setPublicKey(String publicKey) {
  269. this.publicKey = publicKey;
  270. }
  271. public String getCertificateName() {
  272. return certificateName;
  273. }
  274. public void setCertificateName(String certificateName) {
  275. this.certificateName = certificateName;
  276. }
  277. public String getSignPublicKey() {
  278. return signPublicKey;
  279. }
  280. public void setSignPublicKey(String signPublicKey) {
  281. this.signPublicKey = signPublicKey;
  282. }
  283. public String getSignCertificateName() {
  284. return signCertificateName;
  285. }
  286. public void setSignCertificateName(String signCertificateName) {
  287. this.signCertificateName = signCertificateName;
  288. }
  289. public boolean isEtoken() {
  290. return isEtoken;
  291. }
  292. public void setEtoken(boolean isEtoken) {
  293. this.isEtoken = isEtoken;
  294. }
  295.  
  296. Query query = session
  297. .createQuery("select new User(id, userName) from User where id=?");
  298. query.setParameter(0, 1l);
  299.  
  300. DataBaseUtil.createPropertySpecificQuery(Clazz entity, String[] properties, String[] conditionParams, String[] conditionOperators){} write a logic to build query.
Add Comment
Please, Sign In to add comment