Note that there are some explanatory texts on larger screens.

plurals
  1. POhibernate query with composite key,count and netbeans
    text
    copied!<p>I have DLawUserMaster table which has UserID, LoginId and password field. Among them UserId and LoginId are composite key. When user try to login using userID and password, I want to validate user and get userID to store it in session for further use in application.</p> <p>I have tried to get userID using query in netbeans HQL query editor as below.</p> <ol> <li><p>select count(*) from DLawUserMaster user where user.id.loginId='admin' and user.password='admin'</p></li> <li><p>select count(user.id.loginId) from DLawUserMaster user where user.id.loginId='admin' and user.password='admin'</p></li> <li><p>select user.id.userId from DLawUserMaster user where user.id.loginId='admin' and user.password='admin'</p></li> </ol> <hr> <h2>Long | Long | Long | Char</h2> <h2>Blank | Blank | Blank | Blank</h2> <p>blank means empty but it shows 1 row(s) selected.</p> <p>Here is the code UserMaster.java</p> <pre><code>public class DLawUserMaster implements java.io.Serializable { private DLawUserMasterId id; private String userFirstName; private String userMiddleName; private String userLastName; private String password; public DLawUserMaster() { } public DLawUserMaster(DLawUserMasterId id, String userFirstName, String userMiddleName, String userLastName, String password, String address1, String address2, String address3, String city, String state, String pincode, String mobileNo, String stdCode, String phoneNo, String emailId, String hintQuestion, String hintAnswer, Date registrationDate, Date expiryDate, Boolean activate, Integer noOfClientAllowed, Date createdDate, Date modifiedDate) { this.id = id; this.userFirstName = userFirstName; this.userMiddleName = userMiddleName; this.userLastName = userLastName; } public DLawUserMasterId getId() { return this.id; } public void setId(DLawUserMasterId id) { this.id = id; } public String getUserFirstName() { return this.userFirstName; } public void setUserFirstName(String userFirstName) { this.userFirstName = userFirstName; } public String getUserMiddleName() { return this.userMiddleName; } public void setUserMiddleName(String userMiddleName) { this.userMiddleName = userMiddleName; } public String getUserLastName() { return this.userLastName; } public void setUserLastName(String userLastName) { this.userLastName = userLastName; } public String getPassword() { return this.password; } public void setPassword(String password) { this.password = password; } } </code></pre> <p>UserMasterID.java</p> <pre><code>public class DLawUserMasterId implements java.io.Serializable { private long userId; private String loginId; public DLawUserMasterId() { } public DLawUserMasterId(long userId, String loginId) { this.userId = userId; this.loginId = loginId; } public long getUserId() { return this.userId; } public void setUserId(long userId) { this.userId = userId; } public String getLoginId() { return this.loginId; } public void setLoginId(String loginId) { this.loginId = loginId; } public boolean equals(Object other) { if ( (this == other ) ) return true; if ( (other == null ) ) return false; if ( !(other instanceof DLawUserMasterId) ) return false; DLawUserMasterId castOther = ( DLawUserMasterId ) other; return (this.getUserId()==castOther.getUserId()) &amp;&amp; ( (this.getLoginId()==castOther.getLoginId()) || ( this.getLoginId()!=null &amp;&amp; castOther.getLoginId()!=null &amp;&amp; this.getLoginId().equals(castOther.getLoginId()) ) ); } public int hashCode() { int result = 17; result = 37 * result + (int) this.getUserId(); result = 37 * result + ( getLoginId() == null ? 0 : this.getLoginId().hashCode() ); return result; } } </code></pre> <p>Can anyone give me suggestion to get userID value. Also about how to use count in it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload