Hi everyone
This afternoon I faced a problem running Hibernate on a very small system. It actually is an embedded computer running J2ME, but the classpath features all the classes I need to run Spring & Hibernate. Furthermore, the system features about 256MB of RAM, having currently 190MB or so free.
Nevertheless, trying to run my test application including the Spring and Hibernate Library ends up like this:
Code:
[INFO] ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@717f8a9a: display name [org.springframework.context.support.ClassPathXmlApplicationContext@717f8a9a]; startup date [Wed Apr 14 13:41:06 GMT 2010]; root of context hierarchy
[INFO] XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [ch/beo/emc/resources/spring.cfg.xml]
[INFO] ClassPathXmlApplicationContext - Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@717f8a9a]: org.springframework.beans.factory.support.DefaultListableBeanFactory@270d6f70
[INFO] DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@270d6f70: defining beans [ch.beo.emc.persistence.DatabaseDao#0,org.springframework.aop.config.internalAutoProxyCreator,daoAccess,org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0,daoTransactions,dataSource,hibernateSessionFactory,transactionManager]; root of factory hierarchy
[INFO] SingleConnectionDataSource - Loaded JDBC driver: org.sqlite.JDBC
[INFO] Environment - Hibernate 3.2.7
[INFO] Environment - hibernate.properties not found
[INFO] Environment - Bytecode provider name : cglib
[INFO] Environment - using JDK 1.4 java.sql.Timestamp handling
[INFO] HbmBinder - Mapping class: ch.beo.emc.entity.data.Descriptor -> Descriptor
[INFO] HbmBinder - Mapping class: ch.beo.emc.entity.data.Unit -> Unit
[INFO] HbmBinder - Mapping class: ch.beo.emc.entity.data.RawData -> RawData
[INFO] HbmBinder - Mapping joined-subclass: ch.beo.emc.entity.data.TextualRawData -> TextualRawData
[INFO] HbmBinder - Mapping joined-subclass: ch.beo.emc.entity.data.NumericalRawData -> NumericalRawData
[INFO] HbmBinder - Mapping collection: ch.beo.emc.entity.data.NumericalRawData.rawData -> NumericalRawData_rawData
[INFO] HbmBinder - Mapping class: ch.beo.emc.entity.data.Value -> Value
[INFO] HbmBinder - Mapping joined-subclass: ch.beo.emc.entity.data.TextualValue -> TextualValue
[INFO] HbmBinder - Mapping joined-subclass: ch.beo.emc.entity.data.NumericalValue -> NumericalValue
[INFO] HbmBinder - Mapping joined-subclass: ch.beo.emc.entity.data.Quantity -> Quantity
[INFO] HbmBinder - Mapping class: ch.beo.emc.entity.data.Consumption -> Consumption
[INFO] HbmBinder - Mapping class: ch.beo.emc.entity.data.State -> State
[INFO] HbmBinder - Mapping class: ch.beo.emc.entity.meter.MeterType -> MeterType
[INFO] HbmBinder - Mapping class: ch.beo.emc.entity.meter.Meter -> Meter
[INFO] HbmBinder - Mapping class: ch.beo.emc.entity.meter.MeteringPoint -> MeteringPoint
[INFO] HbmBinder - Mapping collection: ch.beo.emc.entity.meter.MeteringPoint.meters -> Meter
[INFO] LocalSessionFactoryBean - Building new Hibernate SessionFactory
[INFO] ConnectionProviderFactory - Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
[WARN] JDBCExceptionReporter - SQL Error: 0, SQLState: null
[ERROR] JDBCExceptionReporter - out of memory
[WARN] SettingsFactory - Could not obtain connection metadata <java.sql.SQLException: out of memory>java.sql.SQLException: out of memory
at org.sqlite.DB.throwex(Unknown Source)
at org.sqlite.NestedDB._open(Unknown Source)
at org.sqlite.DB.open(Unknown Source)
...
[WARN] JDBCExceptionReporter - SQL Error: 0, SQLState: null
[ERROR] JDBCExceptionReporter - out of memory
[ERROR] SchemaUpdate - could not get database metadata <java.sql.SQLException: out of memory>java.sql.SQLException: out of memory
...
[ERROR] SchemaUpdate - could not complete schema update <java.sql.SQLException: out of memory>java.sql.SQLException: out of memory
I am omitting the rest of the trace, but it is obvious that hibernate completely munches my memory. Up from
Code:
[INFO] ConnectionProviderFactory - Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
the memory rapidly drops, until the 180MB memory limit I set is completely used.
From the hibernate manuals I read, however, I take it that 128MB of RAM actually are enough to run Hibernate. Is there any way to constrain Hibernate's excessive memory usage?
My spring.cfg.xml goes like this:
Code:
<bean class="ch.beo.emc.persistence.DatabaseDao" autowire="constructor" />
<aop:config>
<aop:pointcut id="daoAccess"
expression="execution(public * ch.beo.emc.persistence.Dao.*(..))" />
<aop:advisor advice-ref="daoTransactions" pointcut-ref="daoAccess" />
</aop:config>
<tx:advice id="daoTransactions" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" />
</tx:attributes>
</tx:advice>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.SingleConnectionDataSource"
destroy-method="close">
<property name="driverClassName" value="org.sqlite.JDBC" />
<property name="url" value="jdbc:sqlite:emc.db" />
<property name="suppressClose" value="true" />
</bean>
<bean id="hibernateSessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="hibernateProperties">
<map>
<entry key="hibernate.dialect" value="ch.beo.emc.persistence.dialect.SQLiteDialect" />
<entry key="hibernate.show_sql" value="false" />
<entry key="hibernate.hbm2ddl.auto" value="update" />
</map>
</property>
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>ch/beo/emc/resources/hibernate/data.hbm.xml
</value>
<value>ch/beo/emc/resources/hibernate/meter.hbm.xml
</value>
</list>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="dataSource" ref="dataSource" />
<property name="sessionFactory" ref="hibernateSessionFactory" />
</bean>
Thank you very much for any suggestions on this issue and best regards
Kessi