I think your problem is due the recursive nature of the data structure
you are trying to model. Correct if I'm wrong, but "Tabela" is the
classical "Tree". I have already used this kind of structures with
openjpa, and the depth of the tree, is limited by the Java stack.

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Friday, October 05, 2007 3:45 PM
To: users
Subject: Re:Exception in thread "main" java.lang.StackOverflowError

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: [EMAIL PROTECTED]
    Para: "users" [email protected]
      Cc: "dev" [EMAIL PROTECTED]
    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:1
66)
> :
> :
> 
> The error occurrs in the last commit "transaction.commit();" at line
36.
> 
> 
> 
>
 
Confidentiality Statement:
 
This message is intended only for the individual or entity to which it is 
addressed. It may contain privileged, confidential information which is exempt 
from disclosure under applicable laws. If you are not the intended recipient, 
please note that you are strictly prohibited from disseminating or distributing 
this information (other than to the intended recipient) or copying this 
information. If you have received this communication in error, please notify us 
immediately by return email.
-----------------------------

Reply via email to