-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Help to write query.
PostPosted: Fri Feb 11, 2005 8:49 pm 
Beginner
Beginner

Joined: Mon Nov 29, 2004 5:34 pm
Posts: 35
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);


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 1:03 pm 
Beginner
Beginner

Joined: Mon Nov 29, 2004 5:34 pm
Posts: 35
Hi anybody has replies on this. How to deal with table with composite keys and when middlegen is creating 2 domain objects (1 for table and other for keys). How to write a query.

Thanks in Advance.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.