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 8305359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:06:02+00:00 2026-06-08T18:06:02+00:00

I have a StudentInfo table, I need to fetch all the names under name

  • 0

I have a StudentInfo table, I need to fetch all the names under name column in the table.

can any one help me to correct me in the below function

 @Override
 public List<StudentRecord> getAllStudentNames(){

        Session session = HibernateUtil.getSessionFactory().openSession();

     try {

        List<StudentRecord> smrList = new ArrayList<StudentRecord>();

            String SQL_QUERY = "select smr.studentName from StudentRecord as smr";
        Query query = session.createQuery(SQL_QUERY)  

         smrList  = query.list();



        } catch (Exception e) {
            e.printStackTrace();

        } finally {
            session.flush();
            session.close();
            HibernateUtil.getSessionFactory().close();
        }


        return smrList  
    }
  • 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-06-08T18:06:02+00:00Added an answer on June 8, 2026 at 6:06 pm

    You want names, and names are strings, so you don’t want a List<StudentRecord>, but a List<String>.

    The query.list() method returns a List, so there’s no need to create a new ArrayList, only to replace it by the list returned by the method.

    So you just need the following (which respects Java naming conventions):

    String hql = "select smr.studentName from StudentRecord as smr";
    Query query = session.createQuery(hql);  
    List<String> result = query.list();
    return result;
    

    Note that I named the variable hql, and not sql, since HQL and SQL are not the same language, and you’re using HQL here. The above query will work if the persistent property of the StudentRecord class is named studentName. The name of the table and the name of the column are irrelevant, since HQL uses entities for its queries, and not tables.

    Finally, you should not catch Exception: it will only hide errors. Let the exception propagate to the caller.

    It seems you lack basic Java knowledge. I would start by learning Java with simpler problems before using Hibernate, which is a complex framework.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have one Doubt In MVC Architecture we can able to pass data from Controller
i have a program to list the students , it can add new one
Have done quite a bit of searching for a guide (of any substance) for
Have deployed numerous report parts which reference the same view however one of them
have 2 questions : A computer with 32-bit address uses 2-level page table (9
I have public jsonresult update(studentinfo s) { for(i=0;i>0;i++) { var x = // i
I have a partial view called StudentInfo.ascx. In it I have something like this:
I have a view with <%@ Control Language=C# Inherits=System.Web.Mvc.ViewUserControl<IEnumerable<StudentInfo>> %> in my view if
EDIT Thank you all for your assistance. I have made the modifications to the
have Googled the cr*p out of this one so apologies if the answer is

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.