All this is fine for sample apps and smallish installations. However, I personally suggest to neither use the import.sql magic nor the auto-generated schema creation in _real_ production.
Why so? *) Simple because for a real applciation you will later have to add new features, change the db schema and probably also do a migration. *) For a real application you really like to look at the database. Sometimes you get intermediate mapping tables instead of a simple 1:1 if you don’t take care. My generating the schema upfront you can really look at the create table statements. I alsays use the openjpa-maven-plugin for it. For unit tests I use the sql-maven-plugin to create the test database. *) you might like to use liquibase or flywaydb and a schema-version management. I won’t go into details, but check out those 2 projects. Definitly worth looking at. LieGrue, strub > Am 24.04.2015 um 19:11 schrieb Romain Manni-Bucau <[email protected]>: > > 2015-04-24 19:01 GMT+02:00 Kay Wrobel <[email protected]>: > >> Romain: you're right! Derby.jar doesn't ship with TomEE. No clue how that >> ended up in the lib directory. My mistake. >> >> So you're suggesting I use Hibernate? But I have a Derby database and I >> extracted the data as INSERT statements (from Squirrel tool) and it seems >> to contain some Derby-specific stuff, like the notation of date field data >> looks like this: {d '2015-04-24'}. Not sure if Hibernate will take that or >> complain. I would prefer the other solution where I can provide an SQL >> script that is written for that database system (Derby). >> >> > import-<name either of the datasource or the persistence unit>.sql is a > tomee feature not an hibernate one (import.sql). > > PS: if you choose the tomee solution maybe move over tomee@ list > > >>> On Apr 24, 2015, at 11:38 AM, Romain Manni-Bucau <[email protected]> >> wrote: >>> >>> 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 >>>>>> >>>>>> >>>> >>>> >> >>
