César Castro Aroche César Castro Aroche - 2 months ago 8x
Java Question

SQLLite dialect for Hibernate, Table not mapped error

I'm currently developing an app in JavaFX and I'm using an SQLLite database with the sqlite-jdbc- connector, plus for my ORM model I choose the latest Hibernate distribution. The problem I'm getting is that I can't execute queries written by me, despite I successfully managed to Insert, Read, Update and Delete from the database, I can't do it without using the default operations from Hibernate.
These are my configuration settings in the hibernate.cfg.xml file:

<!-- JDBC Database Connection Settings-->
<property name="connection.driver_class">org.sqlite.JDBC</property>
<property name="connection.url">jdbc:sqlite:database.db</property>
<!-- JDBC Connection Pool Settings-->
<property name="connection.pool_size">1</property>
<!-- Selecting SQL Dialect-->
<property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
<!-- Echo the SQL to stdout-->
<property name="show_sql">true</property>
<!-- Set the current session context -->
<property name="current_session_context_class">thread</property>

As you can see, I'm using HSQL Dialect for this database, this is because I can't find a sqlite dialect in the package provided by Hibernate framework. However, as I said before, it works somehow.

So I have a class named Program which is actually a table in the database called Programs. Here is the definition of Program in Java code:

public class Program {

@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "program_id")
protected int program_id;

@Column(name = "name")
protected String name;
@Column(name = "developer")
protected String developer;
@Column(name = "rating")
protected int rating;
@Column(name = "state")
protected int state;
@Column(name = "reservation_date")
protected String reservedDate;
@Column(name = "sent_date")
protected String sentDate;

public Program() {

public Program(String name, int state, LocalDate reservation_date) {
this.name = name;
this.state = state;
this.reservedDate = reservation_date.toString();

Now I have another class named DatabaseConnector which I use to manage database connections. Here is its code:

public class DatabaseConnector {
private final SessionFactory sessionFactory;

public DatabaseConnector() {
sessionFactory = new Configuration()
.addAnnotatedClass(Program.class)//adding table

public Program getProgram(int id) {
Session session = sessionFactory.getCurrentSession();
Program p = session.get(Program.class, id);//captures an object from the database
return program;

As you can see up above there is a getProgram() method which works perfectly.

However, when I try to execute my own query, based on the Hibernate documentation, it should be this way:

public Program getProgram(int id) {
Session session = sessionFactory.getCurrentSession();
List<Program> p = session.createQuery("FROM Programs WHERE Programs.id="+id).list();//This should find an Program
return p.get(0);

This is the error Hibernate shows:

java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: Programs is not mapped [FROM Programs WHERE Programs.id=1]

I must say that this error is not only happening for SELECT operations but every operation I try to execute with my own personal Query. I believe this mistake is related with the database dialect, but I'm not quite sure.


I don't see any reason to believe this is related to the dialect. Your HQL is not correct. Your query should be

"FROM Program p WHERE   p.id="+id

(Note Program, the class name, not Programs, the table name.)

Better still, use parameters in the query:

List<Program> p = session.createQuery("FROM Program p WHERE p.id=:id")
         .setParameter("id", id)

Or, since your are selecting by a field called id, you are presumably expecting a single result in the list:

 Program p = session.createQuery("FROM Program p WHERE p.id=:id")
         .setParameter("id", id)