Guys,
I am using hibernate3 with MySQL 5 on windows. I have a simple SQL query,
List person=session.createSQLQuery("SELECT MAX(x.orderId) FROM PurchaseOrder {x}").addEntity(PurchaseOrderHIB.class).list();
The mapping is,
<class name="PurchaseOrderHIB" table="PurchaseOrder">
<id name="orderId" column="orderId">
<generator class="assigned"/>
The SQL query executes fine inside the MySQL console.
But when i try to execute the same query in my code, i am getting a column not found exception. The stack trace is below: Any idea?
Thanks,
-Uday.
10:52:45,690 DEBUG AbstractBatcher:311 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
10:52:45,700 DEBUG SQL:346 - select max(PurchaseOrder.orderId) from PurchaseOrder
Hibernate: select max(PurchaseOrder.orderId) from PurchaseOrder
10:52:45,700 DEBUG AbstractBatcher:424 - preparing statement
10:52:45,700 DEBUG AbstractBatcher:327 - about to open ResultSet (open ResultSets: 0, globally: 0)
10:52:45,710 DEBUG AbstractBatcher:334 - about to close ResultSet (open ResultSets: 1, globally: 1)
10:52:45,720 DEBUG AbstractBatcher:319 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
10:52:45,720 DEBUG AbstractBatcher:470 - closing statement
10:52:45,730 WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState: S0022
10:52:45,730 ERROR JDBCExceptionReporter:72 - Column 'orderId' not found.
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2150)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2026)
at org.hibernate.loader.Loader.list(Loader.java:2021)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:109)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1475)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:121)
|