I have a cache question using the configuration below. At the start of the application, I went ahead and load all the Loans, Items, Users and here are some of the numbers that I have questions about:
Loan in DB: 1289 ==> 4609 Loan objects were created
Item in DB: 5079 ==> 5969 Item objects were created
User in DB: 6814 ==> 9335 User objects were created
What Am I doing wrong?
Why did I do it this way?
My thought was that since Item are fairly static w/ occasion add and edit, I just permanently put them in the cache so when user view them, no DB access was required. Same thing with User, since User lookup happens a lot. I put them in the cache to minimize the DB access again. The only time we would need to hit the DB is when an Item or User is add or modified or a loan is taken. But from the number above, the math does not work out. If anyone have a better way please let me know. With the current configuration, after about 8 hours the JVM runs out of memory.
I am willing to listen to any suggestions anyone will to give for a better way :-)
Hibernate version: 2.1.6
Mapping documents:
Code:
<hibernate-mapping>
<class name="Item" table="item">
<cache usage="read-write" />
<id column="item_id" length="4" name="itemId" type="integer">
<generator class="native"/>
</id>
<property column="name" length="255" name="name" not-null="true" type="string"/>
<property column="product_name" length="255" name="productName" not-null="true" type="string"/>
<property column="manufacture_date" length="10" name="manufactureDate" type="date"/>
.
.
.
<set name="loans">
<key column="item_id"/>
<one-to-many class="Loan"/>
</set>
</class>
</hibernate-mapping>
Code:
<hibernate-mapping>
<class name="Loan" table="loan">
<cache usage="read-write" />
<id column="loan_id" length="8" name="loanId" type="long">
<generator class="native"/>
</id>
<many-to-one column="item_id" class="Item" name="itemId"/>
<many-to-one class="User" name="userId">
<column name="user_id"/>
<column name="contract_year"/>
</many-to-one>
<property column="loan_type" length="4" name="loanType" not-null="true" type="integer"/>
<property column="loan_date" length="19" name="loanDate"
.
.
.
</class>
</hibernate-mapping>
Code:
<hibernate-mapping>
<class name="User" table="user">
<cache usage="read-write" />
<composite-id name="compId" class="UserPK">
<key-property column="user_id" length="16" name="userId" type="string"/>
<key-property column="contract_year" length="4" name="contractYear" type="string"/>
</composite-id>
<property column="first_name" length="64" name="firstName" not-null="true" type="string"/>
.
.
.
<set name="loans">
<key>
<column name="user_id"/>
<column name="contract_year"/>
</key>
<one-to-many class="Loan"/>
</set>
</class>
</hibernate-mapping>
Code:
[b]ehcache.xml[/b]
<ehcache>
<diskStore path="java.io.tmpdir"/>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"/>
<cache name="Item"
maxElementsInMemory="10000"
eternal="true"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
overflowToDisk="false"/>
<cache name="Loan"
maxElementsInMemory="200000"
eternal="true"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
overflowToDisk="false"/>
<cache name="User"
maxElementsInMemory="10000"
eternal="true"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
overflowToDisk="false"/>
</ehcache>
Code between sessionFactory.openSession() and session.close(): NA
Full stack trace of any exception that occurs: None
Name and version of the database you are using: MySQL 4.0.15
Debug level Hibernate log excerpt: N/A
Thank You
Doug Pham