2015-04-24 18:15 GMT+02:00 Kay Wrobel <[email protected]>: > Re your question about the special need: yes. I want to provide a full > database, the SAMPLE Derby database that ships with NetBeans/Glassfish to a > user who will be testing a specific use case, but under Apache TomEE. > Originally I wanted to provide the entire database as a Derby Database > file/directory inside my web app and then connect to it via the Derby > Embedded driver. I fail to be able to provide the proper JDBC URL so that > TomEE finds that embedded database in my web app directory (not sure where > TomEE even looks at. > > So I decided, well, I would set the database URL to > jdbc:derby:memory:sample;create=true as an in-memory database and simply > run an SQL script that completely creates the database with CREATE TABLE > and INSERT statements. But I didn't know how to instruct the persistence > layer to run that script when the application launches. Which is when I > found the Oracle reference I mentioned earlier, but it is part of JPA 2.1 > as part of the JEE 7 spec. TomEE is based on JEE 6 and JPA 2.0, which > apparently doesn't have that feature. Which is why I turned to the OpenJPA > community to see if that is something OpenJPA can do. Apparently this has > been something EclipseLink and Hibernate had figured out a while ago, but I > want to go with what TomEE provides, which is OpenJPA. TomEE also ships > with the derby.jar, so there's that. > > TomEE doesnt provide derby but hsqldb. In TomEE you can use import-<datasource>.sql or import-<persistenceunit>.sql init scripts for instance. ALso tomee datasource config (commons-bdcp) has such an option. Can be easier alternative to jpa config.
> Please advise. > > Kay > > > On Apr 24, 2015, at 10:59 AM, Jody Grassel <[email protected]> wrote: > > > > That directive will instruct OpenJPA to introspect the databases to > ensure > > the tables needed for the table schema defined by your ORM exists, and > will > > create the table structures automatically if they do not exist. Do you > > have a special need that requires OpenJPA to execute a provided SQL > script? > > > > On Fri, Apr 24, 2015 at 10:54 AM, Kay Wrobel <[email protected]> wrote: > > > >> Thanks, Jody. How will that let me provide an SQL script containing > CREATE > >> TABLE and INSERT statements? > >> > >> Kay > >> > >>> On Apr 24, 2015, at 10:51 AM, Jody Grassel <[email protected]> wrote: > >>> > >>> Add the following property to your persistence unit: > >>> > >>> <property name="openjpa.jdbc.SynchronizeMappings" > >>> value="buildSchema(ForeignKeys=true)"/> > >>> > >>> > >>> > >>> On Fri, Apr 24, 2015 at 10:47 AM, Kay Wrobel <[email protected]> > wrote: > >>> > >>>> Hi everybody. > >>>> > >>>> I am having a rough time finding a way to initialize an Embedded > >> In-Memory > >>>> Derby database in my web application. I found a reference on Oracle's > >> web > >>>> site that states you can initialize a database with DDL and DML > >> statements > >>>> using properties like the following: > >>>> > >>>>> <properties> > >>>>> <property > >>>> name="javax.persistence.schema-generation.database.action" > >>>> value="drop-and-create"/> > >>>>> <property > >>>> name="javax.persistence.schema-generation.create-source" > >> value="script"/> > >>>>> <property > >>>> name="javax.persistence.schema-generation.create-script-source" > >>>> value="META-INF/sql/create.sql" /> > >>>>> <property name="javax.persistence.sql-load-script-source" > >>>> value="META-INF/sql/data.sql" /> > >>>>> </properties> > >>>> > >>>> > >>>> However, that seems to be a new feature in JPA 2.1 spec as part of JEE > >> 6. > >>>> I am working with OpenJPA provided by Apache TomEE, which is > >> openjpa-2.4.0 > >>>> non-final, a JPA 2.0 implementation I would imagine. The current > >> release on > >>>> OpenJPA web site is openjpa 2.3. > >>>> > >>>> Is there a way to accomplish this via JPA 2.0 and/or OpenJPA > >> properties? > >>>> I am trying to initialize an in-memory database for a test case I try > to > >>>> provide to someone. > >>>> > >>>> Any help would be much appreciated. > >>>> > >>>> Kay Wrobel > >> > >> > >
