Lokale Derby in einer JPA-Anwendung

Status
Nicht offen für weitere Antworten.

RoNa

Bekanntes Mitglied
Hallo,

ich habe eine Desktopanwendung, die JPA mit einer lokalen Derby benutzt . Die persistence.xml sieht so aus:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.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_1_0.xsd">
  <persistence-unit name="cowomaPU" transaction-type="RESOURCE_LOCAL">
    <provider>oracle.toplink.essentials.PersistenceProvider</provider>
    <class>de.ronasoft.cowoma.domain.Mitarbeiter</class>
    <class>de.ronasoft.cowoma.domain.Work</class>
    <properties>
      <property name="toplink.jdbc.url" value="jdbc:derby:cowoma-db;create=true"/>
      <property name="toplink.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
      <property name="toplink.ddl-generation" value="create-tables"/>
    </properties>
  </persistence-unit>
</persistence>

Derby.jar muss natürlich im Classpath sein.

Wenn die Datenbank nicht vorhanden ist, wird sie automatisch angelegt. Wenn sie da ist, wird diese genommen.

Es hat nur einen Schönheitsfehler: Beim Start meiner Anwendung mit einer vorhandenen Datenbank bekomme ich die Fehlermeldungen:

Code:
[TopLink Info]: 2009.10.02 08:49:04.963--ServerSession(5965416)--TopLink, version: Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))
[TopLink Info]: 2009.10.02 08:49:08.899--ServerSession(5965416)--file:/D:/projekte/workspaces/netbeans/CoWoMa/bin/-cowomaPU login successful
[TopLink Warning]: 2009.10.02 08:49:09.490--ServerSession(5965416)--Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Table/View 'TBL_MITARBEITER' already exists in Schema 'COWOMA'.
Error Code: 30000
Call: CREATE TABLE cowoma.tbl_mitarbeiter (id INTEGER GENERATED ALWAYS AS IDENTITY NOT NULL, name VARCHAR(255), vorname VARCHAR(255), PRIMARY KEY (id))
Query: DataModifyQuery()
[TopLink Warning]: 2009.10.02 08:49:09.690--ServerSession(5965416)--Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Table/View 'TBL_WORK' already exists in Schema 'COWOMA'.
Error Code: 30000
Call: CREATE TABLE cowoma.tbl_work (id INTEGER GENERATED ALWAYS AS IDENTITY NOT NULL, start TIMESTAMP, ende TIMESTAMP, id_mitarbeiter INTEGER, PRIMARY KEY (id))
Query: DataModifyQuery()
[TopLink Warning]: 2009.10.02 08:49:10.241--ServerSession(5965416)--Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Constraint 'TBLWORKDMTARBEITER' already exists in Schema 'COWOMA'.
Error Code: 30000
Call: ALTER TABLE cowoma.tbl_work ADD CONSTRAINT tblworkdmtarbeiter FOREIGN KEY (id_mitarbeiter) REFERENCES cowoma.tbl_mitarbeiter (id)
Query: DataModifyQuery()

Was mache ich falsch? Hat jemand einen Tipp?

Gruß,

Robert
 
[xml] <property name="toplink.ddl-generation" value="create-tables"/>
[/xml]
Damit legst du fest, dass Toplink jedesmal die create-table Statements erzeugt.
Eine Alternative wäre [c]drop-and-create-tables[/c], was aber zu Fehler führen würde wenn die Tabellen (bzw. die DB) noch nicht angelegt sind.
 
Danke für die Antwort.

Ich will aber, dass wenn die DB vorhanden ist, diese genommen wird und keine DDL-Befehle abgesetzt werden.

Gibt es dafür eine Option in JPA? Muss es eigentlich.

Robert
 
Status
Nicht offen für weitere Antworten.

Zurück
Oben