damnhandy wrote:
Fix,
Can you post your hibernate.cfg.xml, the mappings involved, a sample JUnit that you're executing that includes the interaction withe session? Also, are you running with logging enabled? If not, enable logging and set the following appenders to these levels:
Code:
org.hibernate.SQL=debug
org.hibernate.type=debug
org.hibernate.event.def=trace
Please include that log in your response. Because this log will be fairly large, please only include 1 run of the test. Also, are you using the L2 cache with this test case?
Ryan-
Code:
<?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.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">10000</property>
<property name="hibernate.c3p0.max_size">30</property>
<property name="hibernate.c3p0.max_statements">0</property>
<property name="hibernate.c3p0.min_size">10</property>
<property name="hibernate.c3p0.timeout">10000</property>
-->
<!-- this character enable the utf8 inserting into the database -->
<property name="hibernate.connection.defaultNChar">true</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.password">user</property>
<property name="hibernate.connection.pool_size">15</property>
<property name="hibernate.connection.username">pwd</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.cache.use_query_cache">false</property>
<property name="hibernate.generate_statistics">false</property>
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping schema="TEST" package="com.test">
<class name="TaskDoneView" table="v_task_done" optimistic-lock="none" lazy="false">
<composite-id name="id" class="com.test.TaskDoneView$Id">
<key-property name="itemId" type="integer">
<column name="item_id" not-null="true"/>
</key-property>
<key-property name="messageId" type="integer">
<column name="msg_id" not-null="true"/>
</key-property>
<key-property name="taskId" type="integer">
<column name="task_id" not-null="true"/>
</key-property>
</composite-id>
<property name="itemLabel" type="string" column="item_label" length="13" not-null="true"/>
<property name="messageOriginCountry" type="string" column="msg_item_orig_country" length="2" not-null="true"/>
<property name="messageDestinationCountry" type="string" column="msg_item_dest_country" length="2" not-null="true"/>
<property name="creationDate" type="java.util.Date" column="msg_creation_dt" not-null="true"/>
<property name="taskDescription" type="string" column="task_description" not-null="true"/>
<property name="requestAuthor" type="string" column="req_author" not-null="true"/>
<property name="replyAuthor" type="string" column="rep_author" not-null="true"/>
<property name="originPartnerId" type="integer" column="rep_orig_partner_id" length="4" not-null="true"/>
<property name="originPartnerName" type="string" column="rep_orig_partner_short_name" length="8" not-null="true"/>
<property name="originCallCentreId" type="integer" column="rep_orig_cc_id" length="4" not-null="true"/>
<property name="originCallCentreName" type="string" column="rep_orig_cc_short_name" length="8" not-null="true"/>
<property name="destinationPartnerId" type="integer" column="rep_dest_partner_id" length="4" not-null="true"/>
<property name="destinationPartnerName" type="string" column="rep_dest_partner_short_name" length="8" not-null="true"/>
<property name="destinationCallCentreId" type="integer" column="rep_dest_cc_id" length="4" not-null="true"/>
<property name="destinationCallCentreName" type="string" column="rep_dest_cc_short_name" length="8" not-null="true"/>
<property name="readYN" type="string" column="rep_read_yn" length="1" not-null="true"/>
</class>
</hibernate-mapping>
Code:
Session session = HibernateUtils.getSession();
StringBuffer queryString = new StringBuffer("from TaskDoneView as a where a.destinationPartnerId = :partner and a.creationDate > :now");
if(customQuery==null){
queryString.append(" order by a.creationDate desc");
}
Query query = session.createQuery(queryString.toString());
query.setInteger("partner",partner.getId().intValue());
query.setDate("now",super.getRepliesOffset());
List l = query.list();
That's it. If I run the code that takes so long, I get a debug file of +20 MB, so I'm not gonna paste it in here.
It would be nice however if somebody could just tell me what Hibernate exactly does on the driver class when you create mapping files. It has to do something otherwise my simple testcase with this code ,this mapping and Hibernate.cfg.xlm would also be slow, no?!
For now I've pulled the connection object from hibernate and create my own preparedstatement and now it's working (fast). So I'm happy for now :)