geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mario Kofler" <mario.kof...@gmail.com>
Subject Re: Geronimo 2.0.2 - OpenEJB "Passivation Failed"
Date Mon, 25 Feb 2008 20:20:16 GMT
2008/2/25, Jacek Laskowski <jacek@laskowski.net.pl>:
>
> On Sun, Feb 24, 2008 at 12:31 PM, the666pack <mario.kofler@gmail.com>
> wrote:
>
> >  the only thing i do in the @PreDestroy method is to explicitly close
> the
> >  entity manager via em.close() and then print a line to stdout that the
> >  entitymanager was closed. am i not supposed to close the em?
>
>
> Dave explained why it blew up. What worried me a lot was when you
> wrote that you closed em explicitly? Why are you doing it? Show the
> code so it's simpler to talk about it.



hello.

so there is a simple reason why i  decided to close the entity manager
explicitely: because i thought it is a good idea ;)

so in my "WriteDataBean" class i have more different methods which are all
writing data to the database. One time it is Directors, one time Movies..
and so on. one of these methods, the "writeDirectors" is in the following
code listing:

 private String writeDirectors()
    {

        try
        {
            for(int i=0;i<newDirectors;i++)
            {
                Director d = new Director();
                Calendar c = Calendar.getInstance();
                c.set(1900+i,00,02);
                d.setName("Terry"+i);
                d.setBirthdate(c);
                d.setOrigin("GB");
                em.persist(d);
                em.flush();
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();
            return e.getMessage();
        }

        return "Write to DB success!";
    }

very stupid method which just adds an amount of directors with fixed values
to the database.

so my thought why to put the em.close() in the @PreDestroy was, because i
leave the handle to the em open in this method after em.flush(). then to
close it rightfully i  thought i'd put it into the @PreDestroy method. i
cannot close the em right after em.flush because the SFSB lives longer than
just one call to this particular write method, so if there is a call to
another method, like "writeMovie" the em would be closed already and i get
an exception.

that were my thoughts on this.

thanks,

mario.

Mime
View raw message