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:
I have done the following:
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. 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>
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://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> <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:
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.
If the connection is already setup incorrectly.
jdbc:sqlite:<path to cookbook.sqlite>
If you haven't setup the resource.
To create classes mapped to tables:
There are some tutorials that would probably be worth while to quickly work through even though they also cover some irrelevant material they are not that long.
Getting Started with Java EE Applications
Creating a Simple Web Application Using a MySQL Database
and/or
Take a look at the sample, at File > New Project > Samples > Java EE > Web JPA
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.