简体   繁体   中英

Out of heap memory when executing <jdbc:initalize-database>

Context.xml

<jdbc:initialize-database data-source="dataSource" ignore-failures="ALL">
    <jdbc:script location="classpath:scrubd.sql"/>
</jdbc:initialize-database>

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">  
    <property name="driverClassName" value="org.hsqldb.jdbc.JDBCDriver"/>
    <property name="url" value="jdbc:hsqldb:mem:mydb"/>
    <property name="username" value="sa"/>
    <property name="password" value=""/>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
      depends-on="dataSource"
      name="_sessFac"> 
    <property name="dataSource" ref="dataSource"/>      
    <property name="configLocation" value="hibernate.cfg.xml.incDTD"/>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
            <prop key="hibernate.hbm2ddl.auto">create</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.connection.shutdown">true</prop>
        </props>
    </property>
</bean>

When I am running my ant target on my unit tests, after spring gets initialized the first time, I get an out of memory error. Yet, when I populate my tables by simply naming my database import.sql and letting hibernate handle it, I do not get this out of memory error.

Why does this happen?

Also, it takes Spring about a second longer to load the data in the database than hibernate. Bonus points to anyone that can explain why.

StackTrace (from ant)

Caused by: java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOfRange(Arrays.java:2694)
at java.lang.String.<init>(String.java:234)
at java.lang.StringBuffer.toString(StringBuffer.java:561)
at org.apache.tools.ant.util.StringUtils.replace(StringUtils.java:92)
at org.apache.tools.ant.util.DOMElementWriter.encodedata(DOMElementWriter.java:501)
at org.apache.tools.ant.util.DOMElementWriter.write(DOMElementWriter.java:236)
at org.apache.tools.ant.util.DOMElementWriter.write(DOMElementWriter.java:221)

And the bean causing it has got to be my session factory, since I wouldn't call <jdbc:initialize-database/> a 'bean'.

I want to say based on the stack trace that it is reading the entirety of my sql script into a string, since it is quite large; ~38K lines.

Ended up just saying screw it, and letting hibernate populate my tables. The fact that I am now reading in a 20mB file when doing my unit tests, and I am still not getting an out of memory error with hibernate makes me think that if you want to populate your tables before doing unit tests on them, don't let spring do it. Live and learn.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM