I'm deploying my hibernate beans using the JBoss-hibernate integration code, and so far I have not been able to get named queries to work. These quires worked fine outside of JBoss, but since I migrated to stateless session beans they broke. Everything seems to work fine if I pull the named query into the actuall code that looks it up and use it as a regular query.
Hibernate version: 2.1.5
Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="com.piratefever.hibernate.dbo.Order"
table="orders"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="orderId"
column="id"
type="java.lang.Integer"
unsaved-value="null"
>
<generator class="native">
</generator>
</id>
<timestamp
name="orderDate"
column="order_date"
/>
<property
name="processed"
type="java.lang.Boolean"
update="true"
insert="true"
access="property"
column="processed"
/>
<property
name="customerId"
type="java.lang.Integer"
update="true"
insert="true"
access="property"
column="customer_id "
/>
<set
name="orderItems"
table="ordered_items"
lazy="false"
inverse="false"
cascade="save-update"
sort="unsorted"
>
<key
column="id"
>
</key>
<many-to-many
class="com.piratefever.hibernate.dbo.OrderItem"
column="ordrid"
outer-join="auto"
/>
</set>
<property
name="paymentMethod"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="pmt_method"
/>
<property
name="responseMessage"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="response_msg"
/>
<property
name="resultCode"
type="java.lang.Integer"
update="true"
insert="true"
access="property"
column="result_code"
/>
<property
name="vsignReference"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="reference_id"
/>
<property
name="hostCode"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="host_code"
/>
<property
name="type"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="type"
/>
<property
name="tax"
type="double"
update="true"
insert="true"
access="property"
column="tax"
/>
<property
name="orderIp"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="orderIp"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Order.xml
containing the additional properties and place it in your merge dir.
-->
</class>
<query name="com.piratefever.hibernate.dbo.order.findByDateRange"><![CDATA[
from com.piratefever.hibernate.dbo.Order as ordr where ordr.processed = :showprocessed and ordr.orderDate > :from and ordr.orderDate < :to
]]></query>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
/** @ejb.interface-method
* @see com.piratefever.core.client.InventoryService#getOrdersInDateRange(java.util.Date, java.util.Date, java.lang.String)
*/
public Collection getOrdersInDateRange(Date from, Date to, String status)
throws DataStoreException {
try {
Session sess = HibernateContext.getSession(DBO_SESSION);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Query finder = sess.getNamedQuery("com.piratefever.hibernate.dbo.order.findByDateRange");
finder.setString("from", sdf.format(from, new StringBuffer(), new FieldPosition(0)).toString());
finder.setString("to", sdf.format(to, new StringBuffer(), new FieldPosition(0)).toString());
//REFACTOR (joel) refactor status to a hibernate dependent value object enum thingy.
finder.setString("showprocessed", status.equals("processed")?"1":"0");
return finder.list();
} catch (HibernateException e) {
throw new DataStoreException(e.getMessage());
}
}
Full stack trace of any exception that occurs:Code:
14:08:39,500 ERROR [Engine] StandardWrapperValve[action]: Servlet.service() for servlet action threw exception
com.piratefever.core.exceptions.ApplicationFailureException: Named query not known: com.piratefever.hibernate.dbo.order.findByDateRange
at com.piratefever.core.client.delegate.InventoryDelegate.getOrdersInDateRange(InventoryDelegate.java:63)
at com.piratefever.crm.accounting.struts.LoadOrderListAction.execute(LoadOrderListAction.java:103)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:44)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:169)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:595)