In Java EE, when using JPA to persist classes, my persistance.xml file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="JMonks_Crud">
<jta-data-source>jdbc/example</jta-data-source>
<class>models.Class1</class>
<class>models.Class2</class>
<properties>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="both"/>
</properties>
</persistence-unit>
</persistence>
The only experience so far i have with JPA is from an example that is supposed to clear all the values in the database, then there is servlet's post method to hardcode some values into the used. To accomplish this, the example uses:
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
However I want to persist the data in the database between sessions (like any good dynamic site), and i do not know what to put in the value attribute to do accomplish this. the wikia site (http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#Using_EclipseLink_JPA_Extensions_for_Schema_Generation) says that these are the three different values that it can place in this value:
- none – EclipseLink does not generate DDL; no schema is generated.
- create-tables – EclipseLink will attempt to execute a CREATE TABLE SQL for each table. If the table already exists, EclipseLink will follow the default behavior of your specific database and JDBC driver combination (when a CREATE TABLE SQL is issued for an already existing table). In most cases an exception is thrown and the table is not created. EclipseLink will then continue with the next statement. (See also eclipselink.create-ddl-jdbc-file-name.)
- drop-and-create-tables – EclipseLink will attempt to DROP all tables, then CREATE all tables. If any issues are encountered, EclipseLink will follow the default behavior of your specific database and JDBC driver combination, then continue with the next statement. (See also eclipselink.create-ddl-jdbc-file-name and eclipselink.drop-ddl-jdbc-file-name.)
if I use the none attribute, will it grab the existing tables with populated data? or will none make no tables at all and not help? if i use create-tables, won't i just get an exception thrown? as the table I am trying to use already exists.
thanks for your time :)