Hi Everybody,
I am farily new to Hibernate trying to evaluate the dynamic-class concepts which which ware planning to use in our future projects.
I am really impressed with this new feature, so far i have been able to use the dynamic class concept and perform the following operation,
1. Persist a dynamic class to a table
2. Load a single record from the database into a Map using the session.load method.
3. Display all the records in a table using dynamic class using
List catList = session.createCriteria("<<entity-name>>").list();
4. Generate a Criteria using Hibernate API, Session.createCriteria() method and execut the query and obtain the results.
The one operation that i have been unsuccessful at, is provide a hand crafted HQL to session.createQuery(<<hqlQuery>>) and obtain the results, i get the below mentioned execption when i try to pass a hand written HQL.
I have a simple Cat table in the oracle 9i database, which contain 4 columns
the query with which i am facing the problem is
"from CatPersistentMap"
Here CatPersistentMap is my entity name which maps to a java.util.Map refering to the Cat table in the database, these are configured in the cat.hbm.xml
Hibernate version: 3.0
Mapping documents:
cat.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping auto-import="false">
<import class="java.util.Map" rename="CatPersistentMap"/>
<dynamic-class entity-name="CatPersistentMap" table="Cat" discriminator-value="C" persister="org.hibernate.persister.SingleTableEntityPersister">
<id name="id" type="string" unsaved-value="null" >
<column name="CAT_ID" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<property name="name" type="java.lang.String">
<column name="NAME" length="16" not-null="true"/>
</property>
<property name="sex" type="char"/>
<property name="weight" type="float" />
</dynamic-class>
</hibernate-mapping>
hibernate.cfg.xml
<?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="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.username">scott</property>
<property name="connection.password">tiger</property>
<property name="connection.url">jdbc:oracle:thin:@krishna:1521:qstart</property>
<property name="connection.show_url">true</property>
<property name="hibernate.hbm2ddl.auto">true</property>
<property name="connection.dialect">net.sf.hibernate.dialect.OracleDialect</property>
<property name="hibernate.show_sql">true</property>
<!-- Mapping files -->
<mapping resource="com/accelrys/platform/hibernate/Cat.hbm.xml" />
<!--<mapping resource="com/accelrys/platform/hibernate/CatOwner.hbm.xml" /> -->
</session-factory>
</hibernate-configuration>
Code between sessionFactory.openSession() and session.close():
transaction = session.beginTransaction();
String hqlQuery = "from CatPersistentMap catPersistentMap";
Query query = session.createQuery(hqlQuery);
System.out.println("SQL :: " + query.getQueryString());
List catList = query.list();
if (catList != null && !catList.isEmpty())
{
Iterator catIterator = catList.iterator();
while (catIterator.hasNext())
{
Map catMap = (Map) catIterator.next();
System.out.println("Cat Map :: " + catMap);
}
}
else
System.out.println("Empty records");
transaction.commit();
Full stack trace of any exception that occurs:
Dec 13, 2004 11:50:20 AM org.hibernate.hql.QueryTranslatorImpl logQuery
FINE: SQL: select from
Hibernate: select from
FINE: SQL Exception
java.sql.SQLException: ORA-00936: missing expression
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:579)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1894)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:831)
at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2496)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2840)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:608)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:536)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:96)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1044)
at org.hibernate.loader.Loader.doQuery(Loader.java:321)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:167)
at org.hibernate.loader.Loader.doList(Loader.java:1201)
at org.hibernate.loader.Loader.list(Loader.java:1186)
at org.hibernate.hql.QueryTranslatorImpl.list(QueryTranslatorImpl.java:872)
at org.hibernate.impl.SessionImpl.find(SessionImpl.java:812)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:84)
at com.accelrys.platform.test.TestCatQuery.executeCustomHQL(TestCatQuery.java:164)
at com.accelrys.platform.test.TestCatQuery.main(TestCatQuery.java:53)
SEVERE: Could not execute query
java.sql.SQLException: ORA-00936: missing expression
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:579)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1894)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:831)
at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2496)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2840)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:608)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:536)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:96)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1044)
at org.hibernate.loader.Loader.doQuery(Loader.java:321)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:167)
at org.hibernate.loader.Loader.doList(Loader.java:1201)
at org.hibernate.loader.Loader.list(Loader.java:1186)
at org.hibernate.hql.QueryTranslatorImpl.list(QueryTranslatorImpl.java:872)
at org.hibernate.impl.SessionImpl.find(SessionImpl.java:812)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:84)
at com.accelrys.platform.test.TestCatQuery.executeCustomHQL(TestCatQuery.java:164)
at com.accelrys.platform.test.TestCatQuery.main(TestCatQuery.java:53)
Name and version of the database you are using:
Oracle 9i
The generated SQL (show_sql=true):
Hibernate: select from
Debug level Hibernate log excerpt:
Any help in solving this problem will be highly appreciated.
Peace,
Madhusudan M Krishnamurthy
|