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

  • Home
  • SEARCH
  • 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 4109076
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:44:47+00:00 2026-05-20T21:44:47+00:00

I need to use the following query but i am not able to use

  • 0

I need to use the following query but i am not able to use spring injection so i need to make the query in simple sql.

How can i make the command that don’t uses sessionfactory and any other beans

where registration is my entity class with username and password

public Registration findUserByEmail(String email) {

     try {

          Session session = sessionFactory.getCurrentSession();
          String query = "FROM Registration WHERE email =:email";
          Query query2 = session.createSQLQuery(query); 
          query2.setString("email",email);
          return (Registration) query2.uniqueResult();

     } catch (Exception e) {
                System.out.println(e);
                throw new RuntimeException("DAO failed", e);
            }


    }
  • 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-20T21:44:48+00:00Added an answer on May 20, 2026 at 9:44 pm

    First of all there is no need to make sql query since you have an entity. Hibernate is not dependent on Spring to get the SessionFactory so you don’t have to think about “beans”
    Depending on your configuration (I assume its annotation based), you can create a session factory like –

    SessionFactory sessionFactory = new AnnotationConfiguration()
                                            .configure("classpath/hibernate.cfg.xml")
                                            .buildSessionFactory();
    

    and if it is not annotation based then you can use

    sessionFactory = new Configuration().configure().buildSessionFactory();
    

    this link may help.

    As a side note – if you’re still willing to fire sql (will not recommend though) then do it in plain JDBC.

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

Sidebar

Related Questions

I have the following method that returns void and I need to use it
I have the following links in a sql dump file(.sql). I need to use
I have following complex query which I need to use. When I run it,
I'm trying to make a query that grabs a single row from an SQL
I need to use the SharePoint API in the following way in a PowerShell
I have the following problem: I need to use XSLFO to generate a 2-column
I was following this tutorial . I need to use a php file's ouput
I need to dynamically generate radio or checkbox by jQuery. I use the following
I need following namespaces to use native wpf property grid however, VS 2010 doesn't
Following situation: I need a container for data with a rowindex. Currently we use

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.