Hi,
I use Hibernate 3.2.1ga. I have a relationship one-to-many from Account to Transaction, where the number of transactions per account could be very big. I have mapped this as a Set as follows:
<set name="transactions" table="transaction" lazy="extra">
<key>
... primary key here ...
</key>
<one-to-many class="class name"/>
</set>
In some cases I need to add a new Transaction to the Account, but I'm not interested in loading the full collection, as I'm not interested in any of the existing Transactions, to avoid this I decided to use lazy="extra" in the mapping, as you can see.
The problem is that, even when the collection will not be loaded when adding then Transaction to the collection, Hibernate is loading the collection at flush() time. Notice that when I used lazy="true" it would load the collection as soon as I added the Transaction to the collection.
Is there any way to avoid Hibernate loading the collection at all in this case? In fact the flush() happens at the end of my transaction, so I don't see why anything needs to be loaded at this point (notice that I use Spring 2.0.2 for transaction support).
I have tried adding the Transaction directly through the repository too, (i.e. by doing a saveUpdate() instead of using the collection), but with the same results.
Any help is welcome. In general I'm wondering up to what point is wise to have tables with lots of records mapped as collections, as the performance hit can be quite bad when reading it. Any general ideas/suggestions on this subject as well? Maybe there is some generic pattern out there that be can used in these cases? or maybe Hibernate supports them in some better way?
The following are my Hibernate settings:
Code:
<bean id="hibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.InformixDialect</prop>
<prop key="hibernate.jdbc.batch_size">100</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.auto_import">true</prop>
<prop key="hibernate.bytecode.use_reflection_optimizer">true</prop>
<prop key="hibernate.query.substitutions">true=1,false=0</prop>
<prop key="hibernate.use_outer_join">true</prop>
<prop key="hibernate.max_fetch_depth">3</prop>
<prop key="hibernate.connection.release_mode">auto</prop>
<prop key="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</prop>
<prop key="hibernate.jdbc.use_scrollable_resultset">false</prop>
<prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.SingletonEhCacheProvider</prop>
</props>
</property>
</bean>
Thanks