openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Tilman <>
Subject OOME when using runtime enhancement
Date Thu, 02 Oct 2008 12:42:29 GMT

Hi all,

When attempting to store large entities (with megabytes of blob data) using
OpenJPA runtime enhancement, I get an OOME very quickly. Compile-time
enhancement works OK, unused entity objects are garbage collected.

Heap dump shows that
org.apache.openjpa.util.ImplHelper._unenhancedInstanceMap, a (public) static
Map, is holding hard references to entity objects. From the code I gather
that the intention is to have weak references only (the keys in the map).
But since each entity is also wrapped in a ReflectingPersistenceCapable
(hard reference) and used as value in the map (also hard reference), I don't
think GC will ever occur.

I've experimented with using each entity's identity hashcode as key in the
map instead of the entity object itself. This seems to solve the problem.

Test code to reproduce the problem below. An attempt is made to store 40
photos consecutively with ~1MB of binary data each. Should work with the
default 64MB heap size.

package org.test2;

import javax.persistence.*;

public class Test2 {
	public static void main(String[] args) {
		EntityManagerFactory factory = Persistence

		try {
			for (int i = 1; i <= 40; i++) {
				System.out.println("run=" + i);

				Photo photo = new Photo();
				photo.setData(new byte[1 * 1000 * 1000]);

				persistPhoto(factory, photo);
				photo = null;
		} catch (Throwable t) {

		factory = null;

		// ...

	static void persistPhoto(EntityManagerFactory factory, Photo photo)
			throws Exception {
		final EntityManager em = factory.createEntityManager();
		final EntityTransaction tx = em.getTransaction();


		try {

		} finally {
			if (!tx.isActive()) {

package org.test2;

import javax.persistence.*;

public class Photo {
	@Id @GeneratedValue long id;

	@Basic @Lob byte[] data;

	public byte[] getData() {
		return data;

	public void setData(byte[] data) { = data;

View this message in context:
Sent from the OpenJPA Users mailing list archive at

View raw message