Hi,
I need help in writing function using hibernate query to find records.
I have table (
UserPassword) in database, which has 3 columns.
Quote:
User_ID
Change_date
Password_text
In this table
user_id and change_date are primary key.
When I used middlegen mapping tool, I got
2 classes for this one table
Class User {
Public user() {}
public UserPw (UserPwPK _comp_id) {
super(_comp_id);
}
public
UserPw (
UserPwPK _comp_id,
java.lang.String _pwTxt) {
super (
_comp_id,
_pwTxt);
}
And another class
UserPwPK
public class UserPwPK extends BaseUserPwPK {
public UserPwPK () {}
public UserPwPK (
java.lang.String _userId,
java.util.Date _chgDt) {
super (
_userId,
_chgDt);
}
}
My question is I need to get the write this statement
SQL SELECT PW_TXT
FROM USER_PW
WHERE USER_ID = UPPER (:pUserID)
AND CHG_DT = ( SELECT MAX( CHG_DT )
FROM USER_PW
WHERE USER_ID = UPPER (:pUserID) )
How do I write find Query for the second part to get the max value, this query is not working.
StringBuffer sb = new StringBuffer(100);
sb.append("select MAX(UP. _comp_id ._chgDt) ");
sb.append("from UserPw UP ");
sb.append("where UP. _comp_id._userId = ? ");
UserPwPK a =
(UserPwPK) session.find(
sb.toString(),
aUserPw.getComp_id().getUserId(),
Hibernate.STRING);