0

I saw nearly all questions and answers for this on stackoverflow, but all answers are the same. That you should use something like this Query query = session.createQuery("from theme").list(); but .list() is depricated and I can´t use it anymore.

So the first Question is, what should I use instead of .list()and why I get this exeption java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: theme is not mapped [from theme]

Query Method

public ObservableList<String> getThemes(){
    ObservableList<String> obsList = FXCollections.observableArrayList();
    SessionFactory factory = new Configuration()
                            .configure("hibernate.cfg.xml")
                            .buildSessionFactory();
    Session session = factory.getCurrentSession();
    try {
        session.beginTransaction();
        Query query = session.createQuery("from theme"); // why not mapped 
                                                         //cant use .list()?
        session.getTransaction().commit();
        System.out.println("query " + query);
    } catch (Exception e) {
        e.printStackTrace();
    }finally{
        session.close();
    }
    return obsList;      // nothing at the moment

hibernate.cfg.xml

<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
    <session-factory>
    <property name="connection.driver_class">org.sqlite.JDBC</property>
    <!-- I know sqlite with an mysql dialect isnt the best, in the future it     
will be mySql--> <property
name="connection.url">jdbc:sqlite:C:\\DokiDB\\database.db</property>
    <property name="connection.username">progdm</property>
    <property name="connection.password">release</property>
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="connection.pool_size">1</property>
    <property name="show_sql">true</property>
    <property name="current_session_context_class">thread</property>
</session-factory>
</hibernate-configuration>

mapped class

@Entity
@Table(name="theme")

public class mapTheme {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="theme_id")

private int theme_id;
@Column(name="theme_name")

private String theme_name;
public int getTheme_id() {
    return theme_id;
}

public void setTheme_id(int theme_id) {
    this.theme_id = theme_id;
}

public String getTheme_name() {
    return theme_name;
}

public void setTheme_name(String theme_name) {
    this.theme_name = theme_name;
}

public mapTheme(String theme_name) {
    super();
    this.theme_name = theme_name;
}

public mapTheme(){  
}
}

what can I do?

Blank
  • 489
  • 1
  • 5
  • 11
  • Possible duplicate of [Hibernate error - QuerySyntaxException: users is not mapped \[from users\]](http://stackoverflow.com/questions/9954590/hibernate-error-querysyntaxexception-users-is-not-mapped-from-users) – Xavier Hammond Oct 30 '16 at 14:48
  • @XavierHammond this one, was one of the first answers I found but it didnt helped. And they are using .list() which is depricated and shouldnt be used anymore – Blank Oct 30 '16 at 15:38
  • Ok solved the mapping problem, but I still have the problem, that I dont know how to get my values or data. – Blank Oct 30 '16 at 15:52
  • Why not use a updated hibernate version ? You could type your query with the expected class result type. Why committing to read data ? – davidxxx Oct 30 '16 at 16:19

1 Answers1

0

The table name used in the query is not the name of the table in database, it should be the name of the entity class. In this case you must use

Query query = session.createQuery("from mapTheme");

instead of :

Query query = session.createQuery("from theme")