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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:40:07+00:00 2026-06-17T14:40:07+00:00

Working with hibernate and spring social, I am trying to query the database by

  • 0

Working with hibernate and spring social,

I am trying to query the database by email address.
when i do this query:

public Account findAccountByUsername(String username) {

    Session session = sessionFactory.getCurrentSession();
    String selectQuery = "FROM Account as account WHERE account.username = "+username;
    Query query = session.createQuery(selectQuery);
    @SuppressWarnings("unchecked")
    List<Account> results = query.list();

  if (!results.iterator().hasNext())
        return null;        
    return results.iterator().next();       }

i get this exception

2013-01-22 14:37:13,090 [DEBUG] [HibernateTransactionManager,doBegin(),569] – Exposing Hibernate transaction as JDBC transaction [com.mchange.v2.c3p0.impl.NewProxyConnection@3b249bb2]
2013-01-22 14:37:13,352 [DEBUG] [QueryTranslatorImpl,parse(),272] – parse() – HQL: FROM masterPackage.model.orm.Account as account WHERE account.username = myEmail@gmail.com
2013-01-22 14:37:13,383 [DEBUG] [AbstractPlatformTransactionManager,processRollback(),843] – Initiating transaction rollback
2013-01-22 14:37:13,384 [DEBUG] [HibernateTransactionManager,doRollback(),672] – Rolling back Hibernate transaction on Session [org.hibernate.impl.SessionImpl@294a7134]
2013-01-22 14:37:13,385 [DEBUG] [JDBCTransaction,rollback(),186] – rollback

…….

2013-01-22 14:37:18,818 [WARN] [ProviderSignInController,oauth2Callback(),177] – Exception while handling OAuth2 callback (unexpected char: ‘@’ [FROM masterpackage.model.orm.Account as account WHERE account.username = myEmail@gmail.com]). Redirecting to /signin

is there a way to work around this problem?

There is always a way to save the @ character in the email address as some other character, but i am asking if there is something better then this solution.

  • 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-17T14:40:09+00:00Added an answer on June 17, 2026 at 2:40 pm

    Do not concatenate HQL query. Use named parameters instead. It is an implementation of Query Object Pattern in Hibernate.

    For your case:

    Session session = sessionFactory.getCurrentSession();
    String selectQuery = "FROM Account as account WHERE account.username = :usernameParam";
    Query query = session.createQuery(selectQuery);
    query.setParameter("usernameParam", username);
    @SuppressWarnings("unchecked")
    List<Account> results = query.list();
    
    if(results.isEmpty()){
        return null;
    } else {
        return result;
    }
    

    Offtop: recommended never return null value for such method. Better is to return an empty collection. For example return new ArrayList<>(); Thus you able to use Null Object pattern implicitly.

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

Sidebar

Related Questions

I am working on Spring-Hibernate-Websphere application and sybase as database. Following is the code
I have a database table using an enum. This is already working with hibernate
The project I am working with uses JSF + Spring + Hibernate. This is
I am working in Java project with Spring and Hibernate framework. The database used
I'm working on a Java web application (Adobe Flex front-end, JPA/Hibernate/BlazeDS/Spring MVC backend) and
I'm working on a Spring MVC project in which I'm using Hibernate Validator to
I am working on an application using Spring 3 and Hibernate 3.5 with Java
A project I am working on uses Spring 2.5 & JPA with Hibernate as
I've try to implement integration tests for a working application (spring, hibernate, soap, cxf).
We are working on Java web project based on JPA 2, Hibernate, Spring 3

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.