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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:02:50+00:00 2026-06-13T09:02:50+00:00

I had made class with java class name as Employee and db table name

  • 0

I had made class with java class name as “Employee” and db table name as “EMPLOYEE”. The table had many columns but i had declare only two variables on the employee class. Following is the code of Employee class:

package com.mmi.education;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="EMPLOYEES")
public class Employee {
    private int id;
    private String firstname;
    private String lastname;

    @Id
    @Column(name="EMPLOYEE_ID")
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }

    @Column(name="FIRST_NAME")
    public String getFirstname() {
        return firstname;
    }
    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }
    @Column(name="LAST_NAME")
    public String getLastname() {
        return lastname;
    }
    public void setLastname(String lastname) {
        this.lastname = lastname;
    }

}

On the TestEmployee class, i had written the following code:

package com.mmi.education;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class TestEmployee {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        AnnotationConfiguration config= new AnnotationConfiguration();
        config.configure("hibernate.cfg.xml");

        SessionFactory factory = config.buildSessionFactory();

        Session session = factory.getCurrentSession();
        //session.beginTransaction();
        Query query = session.createQuery("FROM Employee");

        List<Employee> employees = query.list();

        for(Employee employee:employees){
            System.out.println("ID=>"+employee.getId()+"\tFirstName=>"+employee.getFirstname()+"\tLastName=>"+employee.getLastname());
        }
    }

}

Firstly, i am confusing whether to write “FROM EMPLOYEES” or “FROM Employee”.
Secondly, is it safe to declare the two variable in the POJO class (Employee) whereas there are many columns in the table.

Lastly, on executing the code I am facing the following exception:

Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: Employee is not mapped [FROM Employee]

My Database is locally installed (Oracle 10g XE)

  • 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-13T09:02:51+00:00Added an answer on June 13, 2026 at 9:02 am

    HQL only uses entities, mapped properties and associations. Never tables and columns. So the correct query is from Employee.

    If you don’t map all the table columns in your entity, every insert and update in the table will completely ignore the other columns. This means that they will keep their default or current values.

    The exception you get, IIRC, means that you simply forgot to add the entity to the list of mapped entities in the hibernate configuration file.

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

Sidebar

Related Questions

I Made label to had value from database and linked it . but the
I had made one web application in Java using frameworks -struts 2.0, hibernate 3.0,
Whilst programming Java GUis I made heavy use of the Action class. The instantiated
I've had a lot of classes in Java, but this is the first time
I had made three tables. Table1=users .And the column names are userid (auto_increment) and
I had made changes in a folder called branch, and now that its working
I had made a windows service in visual studio 2008 in C#. inside the
EDIT: I had made a mistake during the debugging session that lead me to
I was creating a module and had made a typo and then got a
Upon coding, I realized I had made a mistake. I used git checkout 7e57dbf5a7245...

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.