Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate synchronizer / Composite Key Problem. Need Help

 
srikanth koppisetty
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using middlegen to generate the configuration files and hibernate synchronizer to get the Domain objects.


I need help in writing function using hibernate query to find records.

I have table (UserPassword) in database, which has 3 columns.
User_ID
Change_date
Password_text


In this table user_id and change_date are primary key.
When I used hibernate synchronizer, I got 2 classes for this one table � one for the table and one of the primary key.

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 ( UserID)
AND CHG_DT = ( SELECT MAX( CHG_DT )
FROM USER_PW
WHERE USER_ID = UPPER ( UserID) )



I tired different options, writing query.


UserPwPK a =
(UserPwPK) session.find(
"select MAX(m._chgDt) from com.xyz.test.your.domain.UserPw as PW join PW._comp_id m where m._userId='abc'");
Note:- the above query is for the 2nd part of original SQL, just to test and get results.

(How to access the attributes of primary key class, while writing a query.)

Please help. Thanks in Advance.
 
srikanth koppisetty
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found the Answer, i replaced my string with


select MAX(PW.comp_id.chgDt) from UserPw as PW join PW.comp_id as comp where PW.comp_id.userId = ?",
aUserPw.getComp_id().getUserId(),
Hibernate.STRING);

And it worked.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic