0

my hibernate.cfg.xml is this :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD   3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/****</property>
<property name="hibernate.connection.username">***</property>
<property name="hibernate.connection.password">*****</property>

<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactor    y</property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">false</property>
<property name="hbm2ddl.auto">create</property>
<!-- Enable Hibernate's automatic session context management -->
    <property name="current_session_context_class">thread</property>
<!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">1</property>

<mapping class="entities.MisurazioneOraria"/>
<mapping class=....
    ....>
<listener type="post-insert" class="MisurazioneOrariaInsertListener"/>

</session-factory>

</hibernate-configuration>

i try to do query from this line code that is the listener :

ArrayList<MisurazioneOraria> mis =  (ArrayList<MisurazioneOraria>)    session.createQuery("from (misurazione_oraria) where sensore_idsensore = :idsensore").setParameter("idsensore", m.getSensore().getIdSensore()).list();

and the error is that :

mag 27, 2012 6:30:33 PM org.hibernate.event.def.AbstractFlushingEventListener   performExecutions
Grave: Could not synchronize database state with session
org.hibernate.QueryException: in expected: misurazione_oraria [from (misurazione_oraria) where sensore_idsensore = :idsensore]

my mysql version is 5.5.23. thanks for the help.

1
  • i am seeing the space here 'org.hibernate.hql.classic.ClassicQueryTranslatorFactor y" can u check once.. Commented May 27, 2012 at 17:26

2 Answers 2

1

Your entity class is named MisurazioneOraria, not misurazione_oraria. HQL uses entities and fields/properties. It doesn't use table and column names.

Read the HQL documentation.

Moreover, Query.list() returns a List, and not necessarily an ArrayList. You shouldn't cast the result of the query to ArrayList.

Sign up to request clarification or add additional context in comments.

Comments

0

change it to

List<MisurazioneOraria> mis = session.createQuery("from MisurazioneOraria where idSensore = :idsensore").setParameter("idsensore", m.getSensore().getIdSensore()).list();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.