Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 2.1.6
Mapping documents:
<?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.lastminute.chm.trawler.instance.DefaultCHMProduct" table="drs_product">
<id name="id" column="id">
<generator class="com.lastminute.chm.trawler.persistence.hibernate.V2HibernateIDGenerator">
<param name="table">drs_product</param>
<param name="maxCachedIDs">100</param>
</generator>
</id>
<property name="typeId" column="type_id" type="int"></property>
<property name="hotelName" column="name"></property>
<property name="operatingEntity" column="operating_entity"></property>
<set name="catProducts" cascade="all-delete-orphan" inverse="true" lazy="true">
<key>
<column name="product_id" not-null="true"></column>
</key>
<one-to-many class="com.lastminute.chm.trawler.instance.DefaultCHMProductCategory"/>
</set>
<joined-subclass name="com.lastminute.chm.trawler.instance.DefaultCHMExternalHotel" table="external_hotel">
<key column="product_id"/>
<property name="propertyId" column="property_id"/>
<component class="com.lastminute.chm.trawler.instance.DefaultHotelPriceData" name="hotelPriceData">
<property name="minimumPrice" column="trawl_min_price"></property>
<property name="maximumPrice" column="trawl_max_price"></property>
</component>
</joined-subclass>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
private static final String FIND_ALL_CATEGORY_PRODUCTS = "select distinct prod from DefaultCHMProduct as prod left join fetch "
+ "prod.catProducts as pc join fetch pc.category as cat where prod.typeId=37";
private List findHibernateCategoryHotels() throws PersistenceException, HibernateException {
Session hibernateSession = openSession();
List list = new ArrayList();
try {
Query q = hibernateSession.createQuery(FIND_ALL_CATEGORY_PRODUCTS);
Iterator pairs = q.list().iterator();
while (pairs.hasNext()) {
System.out.println("111111111111112222 pairs.next() " + pairs.next().getClass().getName());
DefaultCHMExternalHotel pair = (DefaultCHMExternalHotel) pairs.next();
Iterator i =pair.getCatProducts().iterator();
while (i.hasNext()){
CHMProductCategory curCatProd = (CHMProductCategory) i.next();
list.add(new DefaultCategoryProductData(curCatProd.getId().getProductId(), curCatProd.getId()
.getCategoryId(), pair.getTypeId(), pair.getPropertyId(), pair.getHotelName(),pair.getOperatingEntity(),
null));
}
}
} catch (Exception e) {
e.printStackTrace();
throw new PersistenceException("Problem in getting the products", e);
} finally {
closeSession(hibernateSession);
}
return list;
}
Full stack trace of any exception that occurs:
16:59:03,178 ERROR (TP-Processor1) [STDERR] java.lang.ClassCastException: com.irfan.chm.trawler.instance.DefaultCHMProduct
16:59:03,178 ERROR (TP-Processor1) [STDERR] at com.irfan.chm.trawler.persistence.hibernate.HibernateCHMTrawlerPersister.findHibernateCategoryHotels()Ljava.util.List;(Optimized Method)
16:59:03,178 ERROR (TP-Processor1) [STDERR] at com.irfan.chm.trawler.persistence.hibernate.HibernateCHMTrawlerPersister.findCategoryHotels()Ljava.util.List;(Optimized Method)
16:59:03,178 ERROR (TP-Processor1) [STDERR] at com.irfan.chm.trawler.engine.DefaultPriceTrawlerEngine.retrieveAllCategoryHotels()Ljava.util.List;(DefaultPriceTrawlerEngine.java:164)
16:59:03,178 ERROR (TP-Processor1) [STDERR] at com.irfan.chm.trawler.engine.DefaultPriceTrawlerEngine.process()V(Optimized Method)
16:59:03,178 ERROR (TP-Processor1) [STDERR] at com.irfan.chm.trawler.jmx.JMXTrawler.process()V(Optimized Method)
16:59:03,178 ERROR (TP-Processor1) [STDERR] at jrockit.reflect.NativeMethodInvoker.invoke0(Ljava.lang.Object;ILjava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
16:59:03,178 ERROR (TP-Processor1) [STDERR] at jrockit.reflect.NativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
16:59:03,178 ERROR (TP-Processor1) [STDERR] at jrockit.reflect.VirtualNativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Optimized Method)
16:59:03,178 ERROR (TP-Processor1) [STDERR] at java.lang.reflect.Method.invoke(Ljava.lang.Object;[Ljava.lang.Object;I)Ljava.lang.Object;(Optimized Method)
16:59:03,178 ERROR (TP-Processor1) [STDERR] at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(Ljava.lang.String;[Ljava.lang.Object;[Ljava.lang.String;)Ljava.lang.Object;(Unknown Source)
16:59:03,178 ERROR (TP-Processor1) [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(Ljavax.management.ObjectName;Ljava.lang.String;[Ljava.lang.Object;[Ljava.lang.String;)Ljava.lang.Object;(Optimized Method)
16:59:03,178 ERROR (TP-Processor1) [STDERR] at org.jboss.jmx.adaptor.control.Server.invokeOpByName(Ljava.lang.String;Ljava.lang.String;[Ljava.lang.String;[Ljava.lang.String;)Lorg.jboss.jmx.adaptor.control.OpResultInfo;(Unknown Source)
16:59:03,178 ERROR (TP-Processor1) [STDERR] at org.jboss.jmx.adaptor.control.Server.invokeOp(Ljava.lang.String;I[Ljava.lang.String;)Lorg.jboss.jmx.adaptor.control.OpResultInfo;(Unknown Source)
16:59:03,178 ERROR (TP-Processor1) [STDERR] at org.jboss.jmx.adaptor.html.HtmlAdaptorServlet.invokeOp(Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse;)V(Unknown Source)
16:59:03,178 ERROR (TP-Processor1) [STDERR] at org.jboss.jmx.adaptor.html.HtmlAdaptorServlet.processRequest(Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse;)V(Unknown Source)
16:59:03,178 ERROR (TP-Processor1) [STDERR] at org.jboss.jmx.adaptor.html.HtmlAdaptorServlet.doPost(Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse;)V(Unknown Source)
16:59:03,178 ERROR (TP-Processor1) [STDERR] at javax.servlet.http.HttpServlet.service(Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse;)V(HttpServlet.java:760)
16:59:03,178 ERROR (TP-Processor1) [STDERR] at javax.servlet.http.HttpServlet.service(Ljavax.servlet.ServletRequest;Ljavax.servlet.ServletResponse;)V(HttpServlet.java:853)
16:59:03,179 ERROR (TP-Processor1) [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Ljavax.servlet.ServletRequest;Ljavax.servlet.ServletResponse;)V(Optimized Method)
16:59:03,179 ERROR (TP-Processor1) [STDERR] at org.apache.catalina.core.ApplicationFilterChain.access$000(Lorg.apache.catalina.core.ApplicationFilterChain;Ljavax.servlet.ServletRequest;Ljavax.servlet.ServletResponse;)V(ApplicationFilterChain.java:98)
16:59:03,179 ERROR (TP-Processor1) [STDERR] at org.apache.catalina.core.ApplicationFilterChain$1.run()Ljava.lang.Object;(ApplicationFilterChain.java:176)
16:59:03,179 ERROR (TP-Processor1) [STDERR] at jrockit.vm.AccessController.do_privileged_exc(Ljava.security.PrivilegedExceptionAction;Ljava.security.AccessControlContext;I)Ljava.lang.Object;(Optimized Method)
16:59:03,179 ERROR (TP-Processor1) [STDERR] at jrockit.vm.AccessController.doPrivileged(Ljava.security.PrivilegedExceptionAction;)Ljava.lang.Object;(Unknown Source)
16:59:03,179 ERROR (TP-Processor1) [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(Ljavax.servlet.ServletRequest;Ljavax.servlet.ServletResponse;)V(ApplicationFilterChain.java:172)
16:59:03,179 ERROR (TP-Processor1) [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(Lorg.apache.catalina.Request;Lorg.apache.catalina.Response;Lorg.apache.catalina.ValveContext;)V(StandardWrapperValve.java:256)
16:59:03,179 ERROR (TP-Processor1) [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Lorg.apache.catalina.Request;Lorg.apache.catalina.Response;)V(Optimized Method)
16:59:03,179 ERROR (TP-Processor1) [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(Lorg.apache.catalina.Request;Lorg.apache.catalina.Response;)V(StandardPipeline.java:480)
16:59:03,179 ERROR (TP-Processor1) [STDERR] at org.apache.catalina.core.ContainerBase.invoke(Lorg.apache.catalina.Request;Lorg.apache.catalina.Response;)V(ContainerBase.java:995)
16:59:03,179 ERROR (TP-Processor1) [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(Lorg.apache.catalina.Request;Lorg.apache.catalina.Response;Lorg.apache.catalina.ValveContext;)V(StandardContextValve.java:191)
16:59:03,179 ERROR (TP-Processor1) [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Lorg.apache.catalina.Request;Lorg.apache.catalina.Response;)V(Optimized Method)
16:59:03,179 ERROR (TP-Processor1) [STDERR] at org.jboss.web.tomcat.security.JBossSecurityMgrRealm.invoke(Lorg.apache.catalina.Request;Lorg.apache.catalina.Response;Lorg.apache.catalina.ValveContext;)V(Unknown Source)
16:59:03,179 ERROR (TP-Processor1) [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Lorg.apache.catalina.Request;Lorg.apache.catalina.Response;)V(Optimized Method)
16:59:03,179 WARN (TP-Processor1) [net.sf.hibernate.util.JDBCExceptionReporter] SQL Warning: 0, SQLState: 01I01
16:59:03,179 WARN (TP-Processor1) [net.sf.hibernate.util.JDBCExceptionReporter] Database has transactions
16:59:03,179 WARN (TP-Processor1) [net.sf.hibernate.util.JDBCExceptionReporter] SQL Warning: 0, SQLState: 01I04
16:59:03,179 WARN (TP-Processor1) [net.sf.hibernate.util.JDBCExceptionReporter] Database selected
16:59:03,180 ERROR (TP-Processor1) [com.irfan.chm.trawler.engine.DefaultPriceTrawlerEngine] Unable to find max and min prices for connectivity hotels for specified date rangescom.irfan.sybil.persistence.PersistenceException: Problem in getting the products
16:59:03,180 INFO (TP-Processor1) [com.irfan.chm.trawler.jmx.JMXTrawler] None of the hotel is unavailable
Name and version of the database you are using:
Informix 9.4
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Hi , Just to add description of the above bug.
DefaultCHMExternalHotels extends DefaultCHMProduct and the query returns list of DefaultCHMProduct and when casting it to DefaultCHMExternalHotel getting ClassCastException.
My requirement is how to access the joined-subcalss's property if we are having return the super class in result.
Thanks & Regards,
Irfan