I'm trying to get up the learning curve on Spring 2.0 and Hibernate 3.0 in Eclipse 3.2 with IBM DB2 version 8. One thing that stumping me at this point is that the HibernateTemplate.loadAll() method is retrieving from the database on every call. As I read the documentation, it's supposed to return the persisted objects, and not go to the database at all.
Here is the console log that shows up every time I refresh the web page that shows all the persons--it shows that Hibernate is accessing the database each time.
13:19:25,159 INFO [RequestInterceptor] Intercepted Request for http://158.158.23.32:8090/frameworkT...tContacts.html
13:19:25,159 INFO [STDOUT] Hibernate: select person0_.PERSON_ID as PERSON1_11_, person0_.FIRST_NAME as FIRST2_11_, person0_.MIDDLE_NAME as MIDDLE3_11_, person0_.LAST_NAME as LAST4_11_ from FRAMEWORK.PERSON person0_
I've attached the pieces that I think are pertinent to the discussion. Any help would be greatly appreciated.
<=============== Person.java ================>
public class Person implements java.io.Serializable {
private static final long serialVersionUID = 5454961752650084595L;
private long personId;
private String firstName;
private String middleName;
private String lastName;
private Set<PersonAddress> personAddresses = new HashSet<PersonAddress>(0);
public Person() {
}
public long getPersonId() {
return this.personId;
}
public void setPersonId(long personId) {
this.personId = personId;
}
public String getFirstName() {
return this.firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getMiddleName() {
return this.middleName;
}
public void setMiddleName(String middleName) {
this.middleName = middleName;
}
public String getLastName() {
return this.lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Set<PersonAddress> getPersonAddresses() {
return this.personAddresses;
}
public void setPersonAddresses(Set<PersonAddress> personAddresses) {
this.personAddresses = personAddresses;
}
public String getFullName() {
return this.firstName + " " + this.middleName + " " + this.lastName;
}
}
<========== Person.hbm.xml ===============>
<?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 27, 2006 11:12:07 AM by Hibernate Tools 3.1.0.beta5 -->
<hibernate-mapping>
<class name="edu.bju.frameworkTest.model.Person" table="PERSON" schema="FRAMEWORK">
<cache usage="read-write" />
<id name="personId" type="long">
<column name="PERSON_ID" />
<generator class="edu.bju.frameworkTest.util.IdGenerator">
<param name="tableName">PERSON</param>
<param name="schema">FRAMEWORK</param>
</generator>
</id>
<property name="firstName" type="string">
<column name="FIRST_NAME" length="15" />
</property>
<property name="middleName" type="string">
<column name="MIDDLE_NAME" length="15" />
</property>
<property name="lastName" type="string">
<column name="LAST_NAME" length="20" />
</property>
<set name="personAddresses" inverse="true">
<cache usage="read-write"/>
<key>
<column name="PERSON_ID" not-null="true" />
</key>
<one-to-many class="edu.bju.frameworkTest.model.PersonAddress" />
</set>
</class>
</hibernate-mapping>
<========== PersonDOAHibernate.java ===============>
public class PersonDAOHibernate extends AbstractHibernateSpringDAO implements PersonDAO {
public ArrayList<Person> findAll() {
return new ArrayList<Person>(super.findAll(Person.class));
}
public ArrayList<Person> loadAll() {
return new ArrayList<Person>(getHibernateTemplate().loadAll(P erson.class));
}
public ArrayList<Person> findAll(String sortColumn) {
return new ArrayList<Person>(super.findAll(Person.class, sortColumn));
}
public Person findById(long personId) {
return (Person) super.load(Person.class, personId);
}
public void save(Person person) {
super.saveOrUpdate(person);
}
public void delete(Person person) {
super.delete(person);
}
}
<========== ehcache.xml ===============>
<ehcache>
<diskStore path="java.io.tmpdir"/>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="86400"
overflowToDisk="true"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"/>
<cache name="org.hibernate.cache.StandardQueryCache"
maxElementsInMemory="10000"
eternal="false"
timeToLiveSeconds="86400"
overflowToDisk="false"/>
</ehcache>
<========== hibernate.cfg.xml ===============>
?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 name="factory">
<property name="hibernate.connection.username">db2pbd</property>
<property name="hibernate.connection.password">db2</property>
<property name="hibernate.connection.url">jdbc:db2://bjuptsrv.bju.edu:50020/BJUPROD</property>
<property name="hibernate.connection.driver_class">com.ibm.d b2.jcc.DB2Driver</property>
<property name="hibernate.dialect">org.hibernate.dialect.DB2 Dialect</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.default_schema">FRAMEWORK</property>
<mapping resource="edu/bju/frameworkTest/model/mapping/Person.hbm.xml" />
</session-factory>
</hibernate-configuration>
<========== framework-context.xml ===============>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans SYSTEM "lib/spring-beans.dtd" >
<beans>
<bean id="factory" name="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
<property name="mappingResources">
<list>
<value>edu/bju/frameworkTest/model/mapping/Person.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.DB2D ialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="format_sql">true</prop>
<prop key="hibernate.cache.provider_class">org.hibernate .cache.EhCacheProvider</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.transaction.flush_before_completion ">true</prop>
</props>
</property>
<property name="dataSource">
<ref bean="dataSource" />
</property><!--
<property name="jtaTransactionManager">
<ref bean="jtaTransactionManager"/>
</property> -->
</bean>
<!-- ===================== DAOs ==================== -->
<bean id="PersonDAOHibernateManaged" parent="txAffirmative">
<property name="target">
<bean class="edu.bju.frameworkTest.model.dao.hibernate.P ersonDAOHibernate">
<property name="sessionFactory" ref="factory" />
</bean>
</property>
</bean>
<!-- ===================== Security ==================== -->
<bean id="filterInvocationInterceptor" parent="baseFilterInvocationInterceptor">
<property name="objectDefinitionSource">
<value>
/editContact.html.*=ROLE_FRAMEWORKTEST_MGR
/.+\.html=ROLE_USER
/.+\.ajax=ROLE_USER
/.+\.jsp=ROLE_USER
/switchUser.jsp.*=ROLE_WEB_DEVELOPER
/j_acegi_switch_user.*=ROLE_WEB_DEVELOPER
</value>
</property>
</bean>
</beans>
<========== framework-servlet.xml ===============>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans SYSTEM "lib/spring-beans.dtd" >
<beans>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
<property name="interceptors">
<list>
<ref bean="requestInterceptor" />
<ref bean="openSessionInView" />
</list>
</property>
<property name="mappings">
<props>
<prop key="/listContacts.html">listContactsController</prop>
<prop key="/editContact.html">editContactController</prop>
</props>
</property>
</bean>
<bean name="requestInterceptor" class="edu.bju.shared.util.spring.RequestIntercept or" />
<bean id="openSessionInView" class="org.springframework.orm.hibernate3.support. OpenSessionInViewInterceptor">
<property name="sessionFactory" ref="factory" />
<property name="singleSession" value="true" />
</bean>
<bean id="listContactsController" class="edu.bju.frameworkTest.controller.ListContac tsController">
<property name="personDAO">
<ref bean="PersonDAOHibernateManaged"/>
</property>
</bean>
<bean id="editContactValidator" class="edu.bju.frameworkTest.controller.validator. EditContactValidator" />
<bean id="editContactController" class="edu.bju.frameworkTest.controller.EditContac tController">
<property name="personDAO" ref="PersonDAOHibernateManaged" />
<property name="sessionForm" value="true" />
<property name="commandName" value="editContactWrapper" />
<property name="commandClass" value="edu.bju.frameworkTest.controller.wrapper.Ed itContactWrapper" />
<property name="validator" ref="editContactValidator" />
<property name="formView" value="editContacts" />
<property name="successView" value="listContacts.html" />
</bean>
</beans>


Reply With Quote
