Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6562859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:45:36+00:00 2026-05-25T13:45:36+00:00

I have the following code on the webservice that uses Hibernate Session session =

  • 0

I have the following code on the webservice that uses Hibernate

Session session = ICDBHibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
User user = (User) session.load(User.class, userid);

userId is a paramter sent from the client.
User class
package com.icdb.data;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

public class User implements java.io.Serializable {

    private Integer userid;
    private String username;
    private String email;
    private String password;
    private String firstname;
    private String lastname;
//  private String streetaddress;
//  private String city;
//  private String phone;
    private String state;
    private String country;
    private Date birthdate;
//  private String zipcode;
    private Set usersesForFavoriteuser = new HashSet(0);
    private Set recipetipses = new HashSet(0);
    private Set recipeses = new HashSet(0);
    private Set recipepictureses = new HashSet(0);
    private Set onlineuserses = new HashSet(0);
    private Set generaltipses = new HashSet(0);
    private Set usersesForFollowinguser = new HashSet(0);
    private Set recipereviewses = new HashSet(0);

    public User() {
    }

    public User(    String username, 
                    String password, 
                    String email, 
                    String firstname,
                    String lastname, 
//                  String streetaddress, 
//                  String city, 
//                  String phone,
                    String state, 
                    String country, 
                    Date birthdate )
//                  String zipcode ) 
    {
        this.username = username;
        this.password = password;
        this.email = email;
        this.firstname = firstname;
        this.lastname = lastname;
//      this.streetaddress = streetaddress;
//      this.city = city;
//      this.phone = phone;
        this.state = state;
        this.country = country;
        this.birthdate = birthdate;
//      this.zipcode = zipcode;
    }

    public User(    String username,
                    String password, 
                    String email,
                    String firstname,
                    String lastname,
//                  String streetaddress, 
//                  String city, 
                    String phone,
//                  String state, 
//                  String country, 
//                  String email, 
                    Date birthdate,
//                  String zipcode, 
                    Set usersesForFavoriteuser, 
                    Set recipetipses,
                    Set recipeses, 
                    Set recipepictureses, 
                    Set onlineuserses,
                    Set generaltipses, 
                    Set usersesForFollowinguser, 
                    Set recipereviewses ) 
    {
        this.username = username;
        this.password = password;
        this.email = email;
        this.firstname = firstname;
        this.lastname = lastname;
//      this.streetaddress = streetaddress;
//      this.city = city;
//      this.phone = phone;
        this.state = state;
        this.country = country;
        this.birthdate = birthdate;
//      this.zipcode = zipcode;
        this.usersesForFavoriteuser = usersesForFavoriteuser;
        this.recipetipses = recipetipses;
        this.recipeses = recipeses;
        this.recipepictureses = recipepictureses;
        this.onlineuserses = onlineuserses;
        this.generaltipses = generaltipses;
        this.usersesForFollowinguser = usersesForFollowinguser;
        this.recipereviewses = recipereviewses;
    }

    public Integer getUserid() {
        return this.userid;
    }

    public void setUserid(Integer userid) {
        this.userid = userid;
    }

    public String getUsername() {
        return this.username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getFirstname() {
        return this.firstname;
    }

    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    public String getLastname() {
        return this.lastname;
    }

    public void setLastname(String lastname) {
        this.lastname = lastname;
    }

//  public String getStreetaddress() {
//      return this.streetaddress;
//  }

//  public void setStreetaddress(String streetaddress) {
//      this.streetaddress = streetaddress;
//  }

//  public String getCity() {
//      return this.city;
//  }

//  public void setCity(String city) {
//      this.city = city;
//  }

//  public String getPhone() {
//      return this.phone;
//  }

//  public void setPhone(String phone) {
//      this.phone = phone;
//  }

    public String getState() {
        return this.state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getCountry() {
        return this.country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Date getBirthdate() {
        return this.birthdate;
    }

    public void setBirthdate(Date birthdate) {
        this.birthdate = birthdate;
    }

//  public String getZipcode() {
//      return this.zipcode;
//  }

//  public void setZipcode(String zipcode) {
//      this.zipcode = zipcode;
//  }

    public Set getUsersesForFavoriteuser() {
        return this.usersesForFavoriteuser;
    }

    public void setUsersesForFavoriteuser(Set usersesForFavoriteuser) {
        this.usersesForFavoriteuser = usersesForFavoriteuser;
    }

    public Set getRecipetipses() {
        return this.recipetipses;
    }

    public void setRecipetipses(Set recipetipses) {
        this.recipetipses = recipetipses;
    }

    public Set getRecipeses() {
        return this.recipeses;
    }

    public void setRecipeses(Set recipeses) {
        this.recipeses = recipeses;
    }

    public Set getRecipepictureses() {
        return this.recipepictureses;
    }

    public void setRecipepictureses(Set recipepictureses) {
        this.recipepictureses = recipepictureses;
    }

    public Set getOnlineuserses() {
        return this.onlineuserses;
    }

    public void setOnlineuserses(Set onlineuserses) {
        this.onlineuserses = onlineuserses;
    }

    public Set getGeneraltipses() {
        return this.generaltipses;
    }

    public void setGeneraltipses(Set generaltipses) {
        this.generaltipses = generaltipses;
    }

    public Set getUsersesForFollowinguser() {
        return this.usersesForFollowinguser;
    }

    public void setUsersesForFollowinguser(Set usersesForFollowinguser) {
        this.usersesForFollowinguser = usersesForFollowinguser;
    }

    public Set getRecipereviewses() {
        return this.recipereviewses;
    }

    public void setRecipereviewses(Set recipereviewses) {
        this.recipereviewses = recipereviewses;
    }

}

also userId defined in the .hbm.xml as

  <id name="userid" type="java.lang.Integer">
   <column name="userid"/>
   <generator class="identity"/>
  </id>

So we have a table of users and another tables that its FK is userId.

I need to update the code to handle the request with a username – and then retrieve the userId instead of the mentioned code of the webservice.

Please help 🙂

Yoav

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:45:37+00:00Added an answer on May 25, 2026 at 1:45 pm
    // I assume username is unique
    
    // username is a parameter
    
    // to get the full user object by name
    String queryString = "from User where username = :username";
    Query query = session.createQuery(queryString);
    query.setString(":username", username);
    User user = (User) query.uniqueResult();
    
    
    // to get just the id
    String queryString = "userid from User where username = :username";
    Query query = session.createQuery(queryString);
    query.setString(":username", username);
    Integer userid = (Integer) query.uniqueResult();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code class User attr_accessor :name end u = User.new u.name =
I have following code snippet that i use to compile class at the run
I'm coding a webservice on python that uses an Oracle database. I have cx_Oracle
I have a WCF Web application that uses a WCF Class Library. My project
I have the following code that I have tested and works: using (new Impersonator(Administrator,
I have the following web service that allows me uploading files: [WebService(Namespace = http://tempuri.org/)]
I have implemented the following functionality that connects to webservice and downloads a favicon
I have some code that when called calls a webservice, queries a database and
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following Code Block Which I tried to optimize in the Optimized section

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.