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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:56:48+00:00 2026-05-29T21:56:48+00:00

Im a newbie to hibernate and I’m facing an error while trying to use

  • 0

Im a newbie to hibernate and I’m facing an error while trying to use Hibernate to select data from a table,
I’ve tried two approaches for this and faced the following errors .

Approach 1

   private static void queryPerson(Session session) {

    String SQL_QUERY ="Select person.ID as ID,person.NAME as NAME ,person.SURNAME AS SURNAME,person.ADDRESS  as ADDRESS From person";
         Query query = session.createQuery(SQL_QUERY);
         for(Iterator it=query.iterate();it.hasNext();){
         Object[] row = (Object[]) it.next();
         System.out.println("ID: " + row[0]);
         System.out.println("Name: " + row[1]);
         System.out.println("Amount: " + row[2]);
         session.getTransaction().commit();
         }

This throws the following error:

 Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: person is not mapped [Select person.ID as ID,person.NAME as NAME ,person.SURNAME AS SURNAME,person.ADDRESS  as ADDRESS From person]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:180)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:111)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:93)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:327)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3441)

Approach 2:

  private static void queryPerson(Session session) {
  Query query = session.createQuery("from Person");                 
    List <Person>list = query.list();
    java.util.Iterator<Person> iter = list.iterator();
    while (iter.hasNext()) {

        Person person = iter.next();
        System.out.println("Person: \"" + person.getName() +"\", " + person.getSurname() +"\", " +person.getAddress());
  session.getTransaction().commit();

    }

Throws the following error:

Caused by: org.postgresql.util.PSQLException: ERROR: column person0_.id does not exist
Position: 8
at    org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
at   org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)

It would be great if anyone could point out where Im going wrong.
Thanks!
EDIT:
Person.hbm.xml

<class name="com.sample.Person" table="Person">

    <id name="id" column="ID">
        <generator class="native" />
    </id>

    <property name="name">
        <column name="NAME" length="16" not-null="false" />
    </property>

    <property name="surname">
        <column name="SURNAME" length="16" not-null="false" />
    </property>

    <property name="address">
        <column name="ADDRESS" length="16" not-null="false" />
    </property>

</class>

hibernate.cfg.xml

    <!-- hibernate dialect -->
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>


    <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
    <property name="hibernate.connection.url">jdbc:postgresql://localhost/testDB</property>
    <property name="hibernate.connection.username">postgres</property>
    <property name="hibernate.connection.password"></property>
    <property name="hibernate.show_sql">true</property> 
    <property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>

    <!-- Automatic schema creation (begin) === -->
    <property name="hibernate.hbm2ddl.auto">validate</property>


    <!-- Simple memory-only cache -->
    <property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>

    <!-- Enable Hibernate's automatic session context management -->
    <property name="current_session_context_class">thread</property>

    <!-- ############################################ -->
    <!-- # mapping files with external dependencies # -->
    <!-- ############################################ -->

    <mapping resource="com/sample/Person.hbm.xml" />

</session-factory>

EDIT: Here is the Person class that Im using:

 package com.sample;

 public class Person {
  Long id;
   String name;
   String surname;
   String address;

public Long getId() {
    return id;
}
private void setId(Long id) {
    this.id = id;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public String getSurname() {
    return surname;
}
public void setSurname(String surname) {
    this.surname = surname;
}
public String getAddress() {
    return address;
}
public void setAddress(String address) {
    this.address = address;
 }
}           
  • 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-29T21:56:50+00:00Added an answer on May 29, 2026 at 9:56 pm

    Try this:

    person.hbm.xml

    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC 
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    
    <hibernate-mapping>
      <class name="com.sample.Person" table="Person">
          <id name="id" column="ID">
            <generator class="native" />
        </id>
        <property name="name">
            <column name="NAME" length="16" not-null="false" />
        </property>
    
        <property name="surname">
            <column name="SURNAME" length="16" not-null="false" />
        </property>
    
        <property name="address">
            <column name="ADDRESS" length="16" not-null="false" />
        </property>
    </class>
    </hibernate-mapping>
    

    hibernate.cfg.xml

    <?xml version='1.0' encoding='utf-8'?>
    <!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    
    <hibernate-configuration>
    <session-factory>
          ...your database configurations and mapping file...
    
    </session-factory>
    </hibernate-configuration>
    

    HibernateUtil.java

    public class HibernateUtil {
    
            private static final SessionFactory sessionFactory;
    
            static {
                try {
                    // Create the SessionFactory from hibernate.cfg.xml
                    // ------ --- -------------- ---- -----------------
                    sessionFactory = new Configuration().configure()
                            .buildSessionFactory();
                } catch (Throwable ex) {
                    // Make sure you log the exception, as it might be swallowed
                    // ---- ---- --- --- --- ---------- -- -- ----- -- ---------
                    System.err.println("Initial SessionFactory creation failed." + ex);
                    throw new ExceptionInInitializerError(ex);
                }
            }
    
            /**
             * Get the configured session factory
             * 
             * @return session factory
             */
            public static SessionFactory getSessionFactory() {
                return sessionFactory;
            }
        }
    

    An example:

    public class PersonExample{
        public static void main(String[] args) {
            Session session = null;
            try {
                SessionFactory sessionFactory = new Configuration().configure()
                        .buildSessionFactory();
                session = sessionFactory.openSession();
                System.out.println("Starting select");
                List<Person> persons= session.createSQLQuery("select {p.*} from Person p").addEntity("p", Person.class).list();
                for (Iterator<Person> it = persons.iterator(); it.hasNext();) {
                Person stObject = it.next();
                   System.out.println("ID: " + stObject.getId());
                   System.out.println("Surname: " + stObject.getSurname());
                   System.out.println("Name: " + stObject.getName());
                   System.out.println("Address: " + stObject.getAddress());
                }
                System.out.println("Finished select");
            } catch (Exception e) {
                System.out.println(e.getMessage());
                e.printStackTrace();
            } finally {
                // Actual contact insertion will happen at this step
                session.flush();
                session.close();
            }
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I m a newbie in Spring Roo. I m trying to use two databases(Mysql).
I am newbie to hibernate. If there is a table which has a composite
Newbie to LINQ, and trying to write the following query... select f.Section_ID, f.Page_ID, f.SortOrder,
I started using Hibernate recently and I'm still a newbie, however, the error I'm
I am a newbie in Hibernate. I am working on a cloud service data
Pardon the newbie question. My data model is really simple (two tables; 200 rows
Hibernate newbie here. I am trying my best to understand Hibernate and ORM in
I am newbie for hibernate,i am using mysql database,with two tables serviceTypeDetails,validateConfig.In serviceTypeDetails,it's having
I am newbie to NHibernate and trying to use Fluent for mapping. My entity
Newbie to .NET data apps here, coming from a Visual Foxpro background. I'm planning

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.