users@glassfish.java.net

Re: RE: JPA: Preload data

From: <glassfish_at_javadesktop.org>
Date: Mon, 09 Mar 2009 12:17:50 PDT

The nice part of the JPA is that it will do this deployment of the schema for you automatically.

The bad part is that you don't get to really participate in the process (it's more of a "driver level" process than application level process).

Sooo...

The hot tip is to simply leverage when the application starts up (using, say, a Servlet or webapp lifecycle listener) and "check" if your database is loaded. For example, you could create a simple control table. If that table has no rows in it, it's safe to assume you have never performed the preload.

At that point, you would then proceed to load data.

One thing that may well work is to simply fetch the data out of your master DB, export it to XML (using, say, XStream), and then use that same mechanism to load from XML in to your Entities, then simply persist them.

If you don't have huge amounts of data, this will likely work painlessly for you.
[Message sent by forum member 'whartung' (whartung)]

http://forums.java.net/jive/thread.jspa?messageID=335913