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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:25:07+00:00 2026-06-15T16:25:07+00:00

I have a problem with a Hibernate query that looks as follows: List persons

  • 0

I have a problem with a Hibernate query that looks as follows:

List persons = getList("FROM creator.models.Person p WHERE p.lastName="+userName);

(the getList(String queryString) method just executes the query using a session factory.)

This is my person class:

@Entity
@Table(name="persons")
public class Person{
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name = "id")
    private Long        id;

    @Column(name="first_name", nullable=false, updatable=true)
    private String firstName;

    @Column(name="last_name", nullable=false, updatable=true)
    private String lastName;
    /// etc

And this is the table:

CREATE TABLE persons(
    id INTEGER NOT NULL AUTO_INCREMENT,
    first_name CHAR(50),
    last_name CHAR(50),
    abbreviation CHAR(4),

    PRIMARY KEY (id)
);

Searching for a person with the name TestName, I get an exception with this message:

org.hibernate.exception.SQLGrammarException: Unknown column 'TestName' in 'where clause'
    at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:82)
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
//etc

The query created by Hibernate looks like this:

INFO: HHH000397: Using ASTQueryTranslatorFactory
Hibernate: select person0_.id as id8_, person0_.abbreviation as abbrevia2_8_, person0_.first_name as first3_8_, person0_.last_name as last4_8_ from persons person0_ where person0_.last_name=TestName
Dec 10, 2012 5:14:26 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions

Searching for the id (...WHERE p.id="3") works fine, by the way!

I hope somebody knows what is going wrong because for me the query looks right and I can’t find out why the lastName is seen as a column name suddenly.

  • 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-15T16:25:09+00:00Added an answer on June 15, 2026 at 4:25 pm

    you need to wrap your parameter with single quotes:

    List persons = getList("FROM creator.models.Person p WHERE p.lastName='"+userName+"'");
    

    but much better with a parameterized query:

            String hql = "FROM creator.models.Person p WHERE p.lastName= :userName";
            Query query = session.createQuery(hql);
            query.setString("userName",userName);
            List results = query.list();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with a query using hibernate. The entity class EntityClass has
I have an interesting problem with hibernate, the model looks like the following: @NamedQueries({
Ok I'm losing on this one. I have an NHibernate query that looks something
I have the Problem that a quite simple select (SELECT h FROM Hero h
I have a problem with Hibernate generating an SQL that do not work on
I'm having a Hibernate query problem, basically it goes like this ... I have
I have a nHibernate query like this ICriteria query = session.CreateCriteria(typeof(MyResult)) .Add(Expression.Eq(ResultTypeId, myResult.ResultTypeId)) Problem
I query my NHibernate datasources using a Linq Expression. The problem I have with
I have a problem with Hibernate Validator 3.1.0.GA not looking up custom validation messages
I have a problem with hibernate and criterias. I have two Classes: public class

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.