I'm trying to use iBatis to insert some data that get sent by a user in a contact us form.
I'm using a Liferay/Spring MVC/iBatis/MySQL setup but I think the problem is caused by the iBatis configuration. Whenever I try to insert data I see an exception in the logs:
com.ibatis.sqlmap.client.SqlMapException: There is no statement named contactus.ibatorgenerated_insert in this SqlMap.
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.getMappedStatement(SqlMapExecutorDelegate.java:231)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.insert(SqlMapExecutorDelegate.java:367)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.insert(SqlMapSessionImpl.java:82)
at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.insert(SqlMapClientImpl.java:58)
The ibator generated sql map does contain an insert query with id "ibatorgenerated_insert" with namespace "contact_us"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMapConfig>
<sqlMap namespace="contactus">
<insert id="ibatorgenerated_insert" parameterClass="contactUs.dao.ContactUs">
<!--
WARNING - This element is automatically generated by Apache iBATIS ibator, do not modify.
This element was generated on Thu Apr 07 15:17:57 BST 2011.
-->
insert into contactus (email_address, first_name, last_name, company, timestamp,
status, message)
values (#emailAddress:VARCHAR#, #firstName:VARCHAR#, #lastName:VARCHAR#, #company:VARCHAR#,
#timestamp:TIMESTAMP#, #status:VARCHAR#, #message:LONGVARCHAR#)
<selectKey resultClass="java.lang.Integer" keyProperty="contactusId">
SELECT LAST_INSERT_ID()
</selectKey>
</insert>
</sqlMap>
</sqlMapConfig>
What can be causing iBatis not to find the statement in the XML file? I assume that it's finding the file since it doesn't report any other kind of error.
I hope that you have specified the contactus.xml file which contains insert statement in the SqlMapConfig.xml as below
<sqlMapConfig>
<properties resource="Connection.properties"/>
<!-- Configure a built-in transaction manager. If you're using an app server, you probably want to use its transaction manager and a managed datasource -->
<settings cacheModelsEnabled="false" enhancementEnabled="true"
lazyLoadingEnabled="true" maxRequests="32" maxSessions="1"
useStatementNamespaces="false" />
<transactionManager type="JDBC">
<dataSource type="JNDI">
<property name="DataSource" value="${connection.datasource}"/>
</dataSource>
</transactionManager>
<!-- List the SQL Map XML files. They can be loaded from the classpath, as they are here (com.domain.data...) -->
<sqlMap resource="contactus.xml"/>
</sqlMapConfig>
Call without namespace.Something like below
sqlMapper.insert("ibatorgenerated_insert",params);
Try adding the following to your <sqlMapConfig> element:
<settings useStatementNamespaces="true"/>
Related
Part of my Java EE application is user management. My development environment is Netbeans 12.0 on Windows 10, JDK 14, Glassfish server 5.1, Apache Derby DB, and the eclipse persistence JPA. Currently, in the development phase, I have configured the JPA to drop and create tables, whenever, I restart the server.
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">
<persistence-unit name="listserviceDB">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:comp/DefaultDataSource</jta-data-source>
<properties>
<property name="eclipselink.ddl-generation.output-mode" value="both"/>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
</properties>
</persistence-unit>
</persistence>
I have an Entity bean "User" that is configured to use Auto-generated primary keys for the entity:
public class User implements Serializable {
private static final long serialVersionUID = 1005L;
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
#NotNull
private String userId;
#NotNull
private String password;
............................
#NotNull
private String userRole;
}
Whenever the server starts, I populated all tables with test data from XML file using JAXB mechanism. Here is a sample of my UserList.xml for the "User" entity bean.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<users>
<user>
<id>2</id>
<userId>AMackinzy</userId>
<password>password</password>
<userRole>update</userRole>
<firstName>Adam</firstName>
<lastName>Mc Keinzy</lastName>
<officePhone>(718)-815-8110</officePhone>
<cellPhone>(845)-340-5410</cellPhone>
<company>MMC</company>
</user>
<user>
<id>3</id>
<userId>AOzguer23</userId>
<password>password</password>
<userRole>consumer</userRole>
<firstName>Albert</firstName>
<lastName>Ozgur</lastName>
<officePhone>(213)-567-2390</officePhone>
<cellPhone>(917)-301-3491</cellPhone>
<company>Bernstern</company>
</user>
<user>
<id>1</id>
<userId>admin</userId>
<password>password</password>
<userRole>superadmin</userRole>
<firstName>Joseph</firstName>
<lastName>Ottaviano</lastName>
<officePhone>718-815-8111</officePhone>
<cellPhone>917-971-6854</cellPhone>
<company>Lemmen Inc.</company>
</user>
</users>
When the application is up and running, I can visually validate the data through the front end JSF (Java Server Faces) pages and everything looks fine, which indicates the JAXB code has successfully loaded the initial user data into the database. The horrid problem starts when I try to add a new User from the front end JSF page that terminates with the following exception:
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.0.v20170811-d680af5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.apache.derby.shared.common.error.DerbySQLIntegrityConstraintViolationException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL201230210444600' defined on 'PERSISTENCE_USER'.
Error Code: 20000
Call: INSERT INTO PERSISTENCE_USER (ID, CELLPHONE, COMPANY, DATEOFBIRTH, FIRSTNAME, LASTNAME, OFFICEPHONE, PASSWORD, USERID, USERROLE) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
bind => [10 parameters bound]
Query: InsertObjectQuery(org.me.mavenlistservicedb.entity.User#79460d95)
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:331)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:905)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:967)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:637)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:564)
at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:2093)
at org.eclipse.persistence.sessions.server.ClientSession.executeCall(ClientSession.java:309)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:270)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:256)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.insertObject(DatasourceCallQueryMechanism.java:405)
at org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:165)
at org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:180)
at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.insertObjectForWrite(DatabaseQueryMechanism.java:502)
at org.eclipse.persistence.queries.InsertObjectQuery.executeCommit(InsertObjectQuery.java:80)
at org.eclipse.persistence.queries.InsertObjectQuery.executeCommitWithChangeSet(InsertObjectQuery.java:90)
at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:314)
at org.eclipse.persistence.queries.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:58)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:911)
I am not sure why I am getting this error when the "User" entity leverages the Auto-key generation, the initial 3 pieces of data have been already loaded into the table, and that the auto-key generator has already been incremented to 4 (assuming the JPA starts generating keys from index=1)? So the first user I add through the JSF front end (which shares the same persistence code as JAXB did to add the initial data from the XML file to the table) should be assigned id=5?
Initially, I thought, maybe the Id fields in the XML file (i.e. 1) had something to do with this error but again with the Auto-key generation scheme, the Id in XML should be overridden by the JPA auto-generated value?
I have already read many posts on this forum and elsewhere regarding the error but didn't find any common denominator with my situation other than the error. Thanks for any lucid explanation of the root cause of this error and how I can fix it without having the application to generate the primary keys.
Update 1: Leftover data in the table
After a thorough investigation, I found out that there are always leftover data in the User table at the application startup, which violates the drop-and-create policy I have selected in the persistence.xml file (perhaps a JPA issue?) In this case, when the container calls my Singleton class #postConstruct annotated method loadData(), to load initial data from an XML file, the auto key generation starts at 1, and that causes conflict with one of the leftover rows having the same Id. I modified the code to delete all rows from the table at the server startup and the problem disappeared, however, I am seeing the following exception in the log file that doesn't cause any problems or interruptions for the application:
Caused by: Exception [EclipseLink-7251] (Eclipse Persistence Services - 2.7.0.v20170811-d680af5): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The attribute [id] of class [org.me.mavenlistservicedb.entity.User] is mapped to a primary key column in the database. Updates are not allowed.
at org.eclipse.persistence.exceptions.ValidationException.primaryKeyUpdateDisallowed(ValidationException.java:2551)
at org.eclipse.persistence.mappings.foundation.AbstractDirectMapping.writeFromObjectIntoRowWithChangeRecord(AbstractDirectMapping.java:1265)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildRowForUpdateWithChangeSet(ObjectBuilder.java:1773)
at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.updateObjectForWriteWithChangeSet(DatabaseQueryMechanism.java:1043)
at org.eclipse.persistence.queries.UpdateObjectQuery.executeCommitWithChangeSet(UpdateObjectQuery.java:84)
at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:314)
at org.eclipse.persistence.queries.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:58)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:911)
at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:810)
at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:108)
at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:85)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2979)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1892)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1874)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1824)
at org.eclipse.persistence.internal.sessions.CommitManager.commitChangedObjectsForClassWithChangeSet(CommitManager.java:273)
at org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsWithChangeSet(CommitManager.java:131)
at org.eclipse.persistence.internal.sessions.AbstractSession.writeAllObjectsWithChangeSet(AbstractSession.java:4384)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabase(UnitOfWorkImpl.java:1491)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1581)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.issueSQLbeforeCompletion(UnitOfWorkImpl.java:3256)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.issueSQLbeforeCompletion(RepeatableWriteUnitOfWork.java:355)
at org.eclipse.persistence.transaction.AbstractSynchronizationListener.beforeCompletion(AbstractSynchronizationListener.java:158)
... 29 more
I am definitely not updating or tampering with any primary keys and I left that task to the auto-generate feature so I am not sure why I am getting this exception? (if source code needed, I would be happy to provide it).
In this case, Eclipse JPA chooses the strategy based on a sequence (the SEQ_GEN sequence created in a database; it calls next value on that sequence), it's not an auto-generated column.
So, in this case the constraint violation exception is understandable - first, on start-up the application creates 3 users with ids: 1, 2, 3 without touching the sequence, and then you try to create the 4th user, but the first value in the sequence is 1.
You can enable the show-sql jpa property to trace SQLs sent to a database.
On selecting from a table called user with jOOQ I get the following exception:
jOOQ; bad SQL grammar [insert into user (user_id, account_type) values (?, ?)]; nested exception is org.postgresql.util.PSQLException: ERROR: syntax error at or near "user"
My jOOQ settings are:
private static final Settings jooqSettings = new Settings()
.withRenderSchema(false)
.withRenderNameStyle(RenderNameStyle.LOWER);
I create a DSLContext from that and construct a query in a transaction as follows:
ctx.insertInto(USER)
.set(USER.USER_ID, userId)
.set(USER.ACCOUNT_TYPE, "U")
.execute()
USER is imported as <jooq-generated-package>.tables.USER.
Does jOOQ have a config property to escape table names (all or just reserved keywords)? I couldn't find anything in the docs or source.
Well, you turned that quoting off by setting RenderNameStyle.LOWER... That's how it works :)
By removing that setting or by setting it to RenderNameStyle.QUOTED, jOOQ will generate those double quotes around all identifiers.
From the specification:
<simpleType name="RenderNameStyle">
<restriction base="string">
<!--
Render object names quoted, as defined in the database. Use this
to stay on the safe side with case-sensitivity and special
characters. For instance:
Oracle : "SYS"."ALL_TAB_COLS"
MySQL : `information_schema`.`TABLES`
SQL Server: [INFORMATION_SCHEMA].[TABLES]
-->
<enumeration value="QUOTED"/>
<!--
Render object names, as defined in the database. For instance:
Oracle : SYS.ALL_TAB_COLS
MySQL : information_schema.TABLES
SQL Server: INFORMATION_SCHEMA.TABLES
-->
<enumeration value="AS_IS"/>
<!--
Force rendering object names in lower case. For instance:
Oracle : sys.all_tab_cols
MySQL : information_schema.tables
SQL Server: information_schema.tables
-->
<enumeration value="LOWER"/>
<!--
Force rendering object names in upper case. For instance:
Oracle : SYS.ALL_TAB_COLS
MySQL : INFORMATION_SCHEMA.TABLES
SQL Server: INFORMATION_SCHEMA.TABLES
-->
<enumeration value="UPPER"/>
</restriction>
</simpleType>
Note, there are feature requests to add more documentation to the Javadoc (#2830) and the manual (#5231)
I am new to esper. I want to store in mysql database event when esper identify event which satisfy the eql query.First i look up this example Esper: How to configure Esper to connect a Relational Database, through a JDBC, using Esper's configuration API and try to come up with solution.
<plugin-loader name="EsperIODBAdapter" class-name="com.espertech.esperio.db.EsperIODBAdapterPlugin">
<config-xml>
<esperio-db-configuration>
<jdbc-connection name="database">
<drivermanager-connection class-name="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/CEP_DEMO"
user="user" password="password"/>
<connection-settings auto-commit="true" catalog="TEST"/>
</jdbc-connection>
<dml connection="database" stream="event" >
<sql>INSERT INTO BasicEvent(userId,eventId,eventUsage,eventDateTime) values(?,?,?,?) </sql>
<bindings>
<bindings>
<parameter pos="1" property="userId"/>
<parameter pos="2" property="eventId"/>
<parameter pos="3" property="eventUsage"/>
<parameter pos="4" property="eventDateTime"/>
</bindings>
</bindings>
</dml>
</esperio-db-configuration>
</config-xml>
</plugin-loader>
Then when i run the application it didn't insert data to table.I want to know my method is correct or is there any other method to configuration.
Thanks
Maybe check that no exceptions are logged or thrown and the you are indeed inserting into a stream called "event" with "insert into event ..."
I have a sample application which loads 2 records ro database and then fetches all the records from DB and prints info from every record.
My problem is follow: when I run program, it fetches only records which inserted on this running, but not before, Also, when I'm opening DB with SQirrel, there is no such database.
Here is my Hibernate config:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:hibertest</property>
<property name="connection.username">sk</property>
<property name="connection.password">0000</property>
<property name="show_sql">true</property>
<property name="current_session_context_class">thread</property>
<property name="hbm2ddl.auto">update</property>
<mapping class="models.Work" />
</session-factory>
</hibernate-configuration>
What I'm doing wrong?
I am not experienced with HSQLDB but try the following URL:
<property name="connection.url">jdbc:hsqldb:file:hibertest;shutdown=true</property>
See: Connection URL documentation.
I believe the default configuration of hsqldb is to not save data on disk for created tables. Please check the hsqldb documentation for how to change this behavior and make tables persistent.
http://hsqldb.org/doc/guide/guide.html#sgc_persist_tables
All the provided answers didn't help me at all.
Currently I use HSQLDB-2.3.2 and hibernate-core-3.5.6 with annotations-3.2.0
In addition to the answer of Tomasz, I needed to manually edit the database script file setting this:
SET WRITE_DELAY 0
You can persist the Data using the HSQL by doing the following,
1.
Connection c = DriverManager.getConnection("jdbc:hsqldb:file:/opt/db/testdb", "SA", "");
"/opt/db/testdb" here is the DB location in the disk.
2. CREATE **TEXT** TABLE <tablename> (<column definition> [<constraint definition>])
3. Assign the source for the Table SET TABLE mytable SOURCE "myfile;fs=|"
Ref: http://hsqldb.org/doc/2.0/guide/texttables-chapt.html
My Github Repository shows the sample https://github.com/Ayyamperumal/HSQL/tree/master/SampleHSQLdb
you can use "Database Development" perspective from Eclipse to see the data. (Supply hsql jar as the driver) Or Execute org.hsqldb.util.DatabaseManager from the hsqldb-*.jar to get the GUI for seeing the data.
I've recently started trying to use Hibernate, but am doing so in Netbeans. This has left me having to use this example project to try and get me up and running.
Unfortunately, at the step "Enumerating Film Titles and Retrieving Actors Using an HQL Query" my HQL queries do not give results and instead fail, with the exception:
org.hibernate.exception.SQLGrammarException: could not execute query
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from limit 100' at line 1
It seems that the HQL isn't generating proper MySQL statements but I can't seem to see why, as I've followed the example to the letter thus far.
I am attempting to connect to a local MySQL database named 'sakila', with the following details:
jdbc:mysql://localhost:3306/sakila
which seems to work correctly as I am able to browse the tables from within Netbeans no problem.
My hibernate.cfg.xml is as follows:
<?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.MySQLInnoDBDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/sakila</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.show_sql">true</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
<mapping resource="dvdrental/Language.hbm.xml"/>
<mapping resource="dvdrental/FilmActor.hbm.xml"/>
<mapping resource="dvdrental/FilmCategory.hbm.xml"/>
<mapping resource="dvdrental/Category.hbm.xml"/>
<mapping resource="dvdrental/Film.hbm.xml"/>
<mapping resource="dvdrental/Actor.hbm.xml"/>
</session-factory>
</hibernate-configuration>
When I'm using the HQL Query window, the SQL it seems to generate only ever says 'select from ' which is obviously wrong, but I can't see why this is being caused?
Edit 1: The HQL Query tab showing my input
Completely stupid reason- I hadn't even thought about the fact I hadn't built the project, so the example code from the bottom of the example ran properly (cause it came pre-compiled). Works no problem now.
I think the main cause of the error is as stated earlier from User, the U in User should be uppercase/capitalized as hibernate uses the POJO. I tried recompiling the code and it works correctly for the sample Swing application: https://netbeans.org/kb/docs/java/hibernate-java-se.html.
However the HQL Query editor still gives this error. It is strange but seems like this editor is not reliable.
The error message 'from limit 100' from your posted exception tells me, that you forgot to add Film after from. Please provide the HQL query that throws the exception.
BTW: the examples in the example project are bad practice. You should never use inline arguments in HQL queries:
from Film as film where film.filmId between '"+startID+"' and '"+endID+"'
You should use query parameters:
Query q = session.createQuery("from Film as film where film.filmId between :startID and :endID");
q.setParameter("startID", startID);
q.setParameter("endID", endID);
When I'm using the HQL Query window, the SQL it seems to generate only ever says 'select from ' which is obviously wrong, but I can't see why this is being caused?
A simple
from Film
is valid HQL and should work. Could you try without the following line:
<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
Not sure this will solve the problem but there is no reason to use the "old" parser anyway.
That replaces the problem with a new one I'm afraid. Now the SQL tab of the HQL pane reports 'Invalid Query', and if I run the query I get org.hibernate.hql.ast.QuerySyntaxException. Any further pointers?
As I said, I was not sure this would solve the problem. What I would do is write a "simple" JUnit test to validate the setup is working. But an obvious bug like this in NetBeans HQL Query window is unlikely, IMO.
Completely stupid reason- I hadn't even thought about the fact I hadn't built the project, so the example code from the bottom of the example ran properly (cause it came pre-compiled). Works no problem now.
I experienced exactly the same problem but I think your stated solution is not correct. Even your project is not compiled HQL will show you results.
One should be careful of Table name in hibernate.cfg.xml file
as it should be same in query (case sensitive) also for example in your case it has table name as "Actor" so
from Actor will work, not from actor