-
Aug 16th, 2011, 07:00 AM
#1
Hibernate coniguration
I have posted this on Hibernate forums but I thought spring people my be able to help me too :)
Hi
I m new to Hibernate and my goal is not to do serious benchmarking testing on Hibernate. It is just to get an idea of how fast you can group data and do calculations in application layer using an ORM tool as oppose to in database. My goal is not to get perfect performance results but reasonable once for Hibernate. In other words, I just want to know that I m not way off concerning performance. However I have now changed my approach and used Spring to configure Hibernate and I think I m getting good results. I have two classes: Customer and CustomerDetail (association one to many) and I m doing grouping and calculations on data in CustomerDetail objects. In the most resent test I have run I have following situation: 1000 Customers and 1000 CustomerDetails for each Customer. The result I m getting is:
Total time to do all calculations: 2810.0 ms
Time to get customers and customerdetails: 40558 ms
This means that I m getting 1000 0000 CustomerDetails in 4 sec that is good right? (Please say if not)
Calculations don’t have anything to do with Hibernate but I m wondering if I can do something to make fetching of objects go even faster. Is there any transaction scope setting or Hibernate configuration I can make that is good for the kind of task that I m performing.
Here is My Hibernate Spring configured XML file I m using JPA annotations for my classes:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence </provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
<!-- value="create" to build a new database on each run; value="update" to modify an existing database; value="create-drop" means the same as "create" but also drops tables when Hibernate closes; value="validate" makes no changes to the database -->
<property name="hibernate.hbm2ddl.auto" value="validate"/>
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.DefaultNamingStrategy"/>
<property name="hibernate.connection.charSet" value="UTF-8"/>
<!-- Uncomment the following two properties for JBoss only -->
<!-- property name="hibernate.validator.apply_to_ddl" value="false" /-->
<!-- property name="hibernate.validator.autoregister_listeners" value="false" /-->
</properties>
</persistence-unit>
</persistence>
And here is my spring ApplicationContext XML file where I m configuring datasource. I m guessing that EntetyManager is wrapper class for Hibernate Session class and EntityManagerFactory is like Hibernates SessionFactory class. Don’t worry about JdbcTemplate bean I m using it for something else.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schem...ng-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schem...ontext-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schem...ng-jee-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:property-placeholder location="classpath*:META-INF/spring/*.properties"/>
<context:spring-configured/>
<context:component-scan base-package="se.dsv" />
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
<property name="driverClassName" value="${database.driverClassName}"/>
<property name="url" value="${database.url}"/>
<property name="username" value="${database.username}"/>
<property name="password" value="${database.password}"/>
<property name="testOnBorrow" value="true"/>
<property name="testOnReturn" value="true"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="1800000"/>
<property name="numTestsPerEvictionRun" value="3"/>
<property name="minEvictableIdleTimeMillis" value="1800000"/>
</bean>
<bean class="org.springframework.orm.jpa.JpaTransactionM anager" id="transactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<bean class="org.springframework.jdbc.core.JdbcTemplate" id="jdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean" id="entityManagerFactory">
<property name="persistenceUnitName" value="persistenceUnit"/>
<property name="dataSource" ref="dataSource"/>
</bean>
</beans>
Thank you for your help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules