openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ricardo.leon...@bol.com.br
Subject Re:Exception in thread "main" java.lang.StackOverflowError
Date Fri, 05 Oct 2007 02:02:25 GMT
Sorry,

Here the source code.
Please help me.


Teste.java
============================================================================
import java.util.Iterator;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

public class Teste {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		EntityManagerFactory emf;
		emf = Persistence.createEntityManagerFactory("default", System
				.getProperties());
		EntityManager em = (EntityManager) emf.createEntityManager();
		EntityTransaction transaction = em.getTransaction();

		transaction.begin();
		for (int x = 0; x < 1000; x++) {
			em.persist(new Tabela(x, "Id " + x));
		}
		transaction.commit();

		
		transaction.begin();
		List l = (List<Tabela>) em.createQuery("SELECT a FROM Tabela a")
				.getResultList();
		Iterator i = l.iterator();
		while (i.hasNext()) {
			Tabela tb = (Tabela) i.next();
			System.out.println(tb);
		}
		transaction.commit();

	}

}
============================================================================


Tabela.java
============================================================================

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import org.apache.openjpa.persistence.InverseLogical;

@Entity
public class Tabela implements Serializable {

	private static final long serialVersionUID = -7323896668494281866L;

	@Id
	private int id;

	private String ds;

	@ManyToOne(cascade = CascadeType.REFRESH)
	@JoinColumn(name = "pai", nullable = true)
	private Tabela pai;

	@OneToMany(cascade = CascadeType.REFRESH, mappedBy = "pai")
	@InverseLogical("pai")
	private List<Tabela> filhos;
	
	public Tabela(int i, String x) {
		id = i;
		ds = x;
	}

	public String getDs() {
		return ds;
	}

	public void setDs(String ds) {
		this.ds = ds;
	}

	public int getId() {
		return id;
	}

	public void setId(int a) {
		this.id = a;
	}

	public Tabela() {
		super();
	}

	public String toString() {
		return "" + id + " " + ds;
	}

	public List<Tabela> getFilhos() {
		return filhos;
	}

	public void setFilhos(List<Tabela> filhos) {
		this.filhos = filhos;
	}

	public Tabela getPai() {
		return pai;
	}

	public void setPai(Tabela pai) {
		this.pai = pai;
	}

}
============================================================================


tnks
[]s


---------- InĂ­cio da mensagem original -----------

      De: ricardo.leoneti@bol.com.br
    Para: "users" users@openjpa.apache.org
      Cc: "dev" dev@openjpa.apache.org
    Data: Tue,  2 Oct 2007 20:28:44 -0300
 Assunto: Exception in thread "main" java.lang.StackOverflowError

> Guys,
> 
> I do a simple teste and I found that error:
> Exception in thread "main" java.lang.StackOverflowError
> 	at java.security.AccessController.doPrivileged(Native Method)
> 	at org.apache.openjpa.enhance.Reflection.getDeclaredField(Reflection.java:166)
> :
> :
> 
> The error occurrs in the last commit "transaction.commit();" at line 36.
> 
> 
> 
> 


Mime
View raw message