vendredi 9 octobre 2015

SQLite, NetBeans, EclipseLink and JPA - NetBeans keeps starting Apache Derby instead of SQLite DB

I'm struggling with NetBeans and failing to make a project (Vaadin -> Maven-based) that connects to an SQLite database. For some reason every time I run my project:

  • NetBeans starts an Apache Derby database
  • JPA doesn't generate tables in my SQLite table (probably since I never manage to connect to it)

I have done the following:

  1. "Install" the SQLite JDBC driver - downloaded the jar, went to Services -> Database and created a new connection pointing at the jar. I've named it SQLite 3.8.11.2. It has been successfully added and listed under Databases -> Drivers.
  2. Adding a connection to the database - the database is created using the command line tool and is located inside the root directory of the NetBeans Maven project. Currently it is empty since I want to use JPA to generate my tables from the respective entity classes. I added the connection and it points to the cookbook.sqlite file. In order to check if things are working at this stage I created a small table using NetBeans' user interface, added a bunch of stuff and then using the terminal checked if the database file has changed and what it contains. No problems here.
  3. Resolve Maven dependecies - to the <dependencies/> inside the pom.xml of my project I added:

    <dependencies>
    
      <!-- various other dependencies mostly related to Vaadin -->
      ...
    
      <dependency>
        <groupId>javax.persistence</groupId>
        <artifactId>persistence-api</artifactId>
        <version>1.0.2</version>
      </dependency>
    
      <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>eclipselink</artifactId>
        <version>2.5.2</version>
        <scope>provided</scope>
      </dependency>
    
      <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
        <version>2.5.2</version>
        <scope>provided</scope>
      </dependency>
    </dependencies>
    
    
  4. Created a persistence unit - I have 3 entity classes - User, Ingredient and Recipe. The generated persistence.xml contains:

    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="2.1" xmlns="http://ift.tt/1cKbVbQ" xmlns:xsi="http://ift.tt/ra1lAU" xsi:schemaLocation="http://ift.tt/1cKbVbQ http://ift.tt/1kMb4sd">
      <persistence-unit name="CookbookPU" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <non-jta-data-source>cookbook_db</non-jta-data-source>
        <class>com.ava.cookbook.models.User</class>
        <class>com.ava.cookbook.models.Ingredient</class>
        <class>com.ava.cookbook.models.Recipe</class>
        <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
        <properties>
          <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
          <property name="javax.persistence.jdbc.driver" value="org.sqlite.JDBC"/>
          <property name="javax.persistence.jdbc.url" value="jdbc:sqlite:/PATH_TO_PROJECT_ROOT/cookbook_db.sqlite"/>
          <property name="javax.persistence.jdbc.user" value="cookbook"/>
          <property name="javax.persistence.jdbc.password" value="cookbook"/>
          <property name="eclipselink.logging.level" value="FINEST"/>
        </properties>
      </persistence-unit>
    </persistence>
    
    

Note that the schema generation is set to drop-and-create.

Basically these are my settings. When I try to run the project in the output window four new tabs appear:

  • Run (Cookbook) - this one tells me information about the state of the running project (since I haven't started actually accessing the database (which I cannot connect to :3) it runs perfectly fine)
  • GlassFish Server 4.1 - information about the GlassFish server that the project is running on
  • Browser Log - I'm using the NetBeans connector and while running the Vaadin project inside Google Chrome this tab displays a bunch of Vaadin-related events
  • Java DB Database Process - this one is the bummer in all this. In detail the messages here are:

    Fri Oct 09 15:02:47 CEST 2015 : Security manager installed using the Basic server security policy.
    Fri Oct 09 15:02:48 CEST 2015 : Apache Derby Network Server - 10.11.1.2 - (1629631) started and ready to accept connections on port 1527
    
    

Before I saw that I was thinking that I've screwed things up with the whole JPA-Entity-thing but after I noticed the second message in particular it became obvious that the project not connecting to the SQLite database but running it's own Derby DB.

I have barely any experience with Maven, EclipseLink, JPA and NetBeans so it is quite possible I'm overlooking something. Some advice or even a solution would be much appreciated.

Aucun commentaire:

Enregistrer un commentaire