Hi,
I am having trouble using hibernate in a series of select statements . An example is one method might have an sql statement that returns 2000 records and each record has an associated object as one of it's properties.
In the applications method I use the following to retrieve the data for the objects Fielding and each associated Master object :
Code:
retVals.addAll(session.createSQLQuery("Select f.* ,m.* from Fielding f,Master m where f.lgID='"+ league + "' and f.yearID = "+ yr +" and f.playerId = m.playerID")
.list());
The mapping file is such :
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jul 18, 2009 3:03:12 PM by Hibernate Tools 3.2.2.GA -->
<hibernate-mapping>
<class name="baseball.hibernate.Fielding" table="fielding">
<cache usage="read-write" />
<composite-id name="id" class="baseball.hibernate.FieldingId">
<key-property name="playerId" type="string">
<column name="playerID" length="9" />
</key-property>
<key-property name="yearId" type="short">
<column name="yearID" />
</key-property>
</composite-id>
<property name="playerId" type="string" insert="false" update="false" >
<column name="playerID" length="9" />
</property>
<property name="yearId" type="short" insert="false" update="false">
<column name="yearID" />
</property>
<property name="teamId" type="string">
<column name="teamID" length="3" not-null="true" />
</property>
<property name="lgId" type="string">
<column name="lgID" length="2" not-null="true" />
</property>
<property name="g" type="java.lang.Short">
<column name="G" />
</property>
<many-to-one name="master" column="playerID" entity-name="baseball.hibernate.Master" property-ref="playerId" insert="false" update="false" />
</class>
</hibernate-mapping>
The problem is that it takes a day and a half(not literally but it's very slow) to run and retrieve the objects .
The problem is compounded by the fact that I have to run a series of similar methods from one user action . The objects are then used to display data .
This project is basically a learning exercise and what I'm learning is that Hibernate is terrible for applications/methods where you only have to retrieve data, if it is more than a small number of records.
Apparently, there is no way around around having to retrieve and open/getCurrentSession a session object and create a transaction object within each sub method.
In an ideal world I would open the session once . Start a transaction . Call all the data retrieval methods and then close the transaction and session. This would at least save the overhead and time of opening and closing many sessions and transactions when one would do.
As this isn't an unusual task,I'm probably missing some key point or strategy for using hibernate to do this .
Does anybody know how I should be doing this using Hibernate ?
thanks,
Paul