Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.0.3
Mapping documents:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="DETECTION_ENGINE_TRADE_SURVEILLIANCE">
<property name="show_sql">false</property>
<property name="hibernate.dialect">org.hibernate.dialect.DB2Dialect</property>
<property name="hibernate.connection.driver_class">com.ibm.db2.jcc.DB2Driver</property>
<property name="hibernate.connection.url"></property>
<property name="hibernate.connection.username"></property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.default_schema"></property>
<property name="hibernate.jdbc.fetch_size">2</property>
<property name="hibernate.default_batch_fetch_size">2</property>
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.max_size">10</property>
<property name="hibernate.c3p0.min_size">0</property>
<mapping resource="com/gs/fw/gc/ds/das/db/orm/map/Trade.hbm.xml"/>
<mapping resource="com/gs/fw/gc/ds/das/db/orm/map/Product.hbm.xml"/>
<mapping resource="com/gs/fw/gc/ds/das/db/orm/map/Account.hbm.xml"/>
</session-factory>
</hibernate-configuration>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping schema="amlusprod" default-lazy="false">
<class name="com.gs.fw.cmpl.de.data.Account" table="Account_View" lazy="false" batch-size="10">
<cache usage="read-only"/>
<id name="accountId" type="string" unsaved-value="null" >
<column name="sub_acct_c" not-null="true"/>
</id>
<set name="productList" inverse="true" lazy="false" order-by="sub_acct_c ASC, prime_id_c ASC">
<cache usage="read-only"/>
<key column="sub_acct_c"/>
<one-to-many class="com.gs.fw.cmpl.de.data.Product" />
</set>
</class>
<query name="DE_ACCTS_WITH_TRADES">
<![CDATA[
from Account order by accountId
]]>
</query>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping schema="amlusprod" default-lazy="false">
<class name="com.gs.fw.cmpl.de.data.Product" table="Product_View" lazy="false">
<cache usage="read-only"/>
<id name="productId" type="string" unsaved-value="null" >
<column name="prime_id_c" not-null="true"/>
</id>
<set name="tradeList" inverse="true" lazy="false" order-by="prime_id_c ASC">
<cache usage="read-only"/>
<key column="prime_id_c"/>
<one-to-many class="com.gs.fw.cmpl.de.data.Trade" />
</set>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping schema="amlusprod" default-lazy="false">
<class name="com.gs.fw.cmpl.de.data.Trade" table="Trade_View" lazy="false">
<cache usage="read-only"/>
<composite-id>
<key-property name="tradeDate" column="trade_date_d" type="date"/>
<key-property name="tranValue" column="post_amt_c" type="double"/>
<key-property name="tranQty" column="sec_qty_c" type="double"/>
</composite-id>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Iterator<Account> iter = (session.getNamedQuery(_namedQuery)).iterate();
end = System.currentTimeMillis();
duration = end - start;
System.out.println("HIBERNATE SELECT NQ DURATION: "+duration);
List<Account> acctList = new ArrayList<Account>();
start = System.currentTimeMillis();
while ((iter != null) && iter.hasNext())
{
startrow = System.currentTimeMillis();
acct = iter.next();
acctList.add(acct);
end = System.currentTimeMillis();
duration = end - startrow;
System.out.println("HIBERNATE NEXT: "+duration);
}
Full stack trace of any exception that occurs:
Name and version of the database you are using:
DB2 UDB 8.x
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
General Question about how I can improve performance:
I have the object graph:
Account with many products and products with many trades....
I thought if I set the fetch size it would load that number of the parent objects plus all its children??
I would like to use an iterator, because there can be over 1 million rows. I saw in the documentation:
11.4.1.1. Iterating results
Occasionally, you might be able to achieve better performance by executing the query using the iterate() method. This will only usually be the case if you expect that the actual entity instances returned by the query will already be in the session or second-level cache. If they are not already cached, iterate() will be slower than list() and might require many database hits for a simple query, usually 1 for the initial select which only returns identifiers, and n additional selects to initialize the actual instances.
QUESTION:
1. What can I set, so Hibernate can fetch 10 rows and initialize 10 (or more) instances at a time??