• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to create database tables from Netbeans via JPA

 
Mike Cheung
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm following the YouTube tutorial here to create the JPA entity classes from the Java Derby sample tables successfully. But unlike the video, I am not able to re-create the tables on the database after I deleted them. Any ideas?
https://www.youtube.com/watch?v=TDbZ5EGpvoY&feature=youtu.be

This is the persistent unit I'm using. Note the "drop-and-create-tables" setting is applied.


One thing I'm not sure is whether there are additional settings the YouTube author have applied. This is because the main method shown in the video have a number of JPA code in it whereas mine only have the following ...


I have tried to change it to the following ...


When I run it, I get the following error ...



I then right click on the Libraries folder, and added the EclipseLink (JPA 2.1) library. This added the following ...
EclipseLink (JPA 2.1) - eclipselink.jar
EclipseLink (JPA 2.1) - javax.persistence_2.1.0v201304241213.jar
EclipseLink (JPA 2.1) - org.eclipse.persistence.jpa.jpql_2.5.1.v20130918-f2b9fc5.jar

When I run it, I get the following error ...
 
Mike Cheung
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I found the solution! This is what I needed to do ...
Step 1 - Add the DB Driver
In this case I'm using Java DB and because I haven't added the Java DB's JDBC Driver, it's complaining with Class [org.apache.derby.jdbc.ClientDriver] not found.
Right click on Libraries folder -> Add Library
Select Java DB Driver

Step 2 - Add the JPA Provider (EclipseLink is the one I'm using)
Right click on Libraries folder -> Add Library
Select either EclipseLink (JPA 2.1) or EclipseLink from Glassfish. Note EclipseLink-ModelGen (JPA 2.1) doesn't work because package javax.persistence does not exist.

The above 2 steps were what's missing in my project.

Now just to try things out a bit, I tried to use the Hibernate Persistence Library by updating my persistence.xml to the following ...


And then added the Hibernate's JPA Provider by ...
Right click on Libraries folder -> Add Library
Select Hibernate 4.x (JPA 2.0)

But for some reason when I run the project, I'm getting the following ...



Any ideas?
 
K. Tsang
Bartender
Posts: 3585
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error is:
Caused by: org.hibernate.AnnotationException: Cannot find the expected secondary table: no MICRO_MARKET available for JPATest2_EntityClasses.MicroMarket

So what's "MICRO_MARKET"? How are you using/creating/mapping this table?
 
Mike Cheung
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:The error is:
Caused by: org.hibernate.AnnotationException: Cannot find the expected secondary table: no MICRO_MARKET available for JPATest2_EntityClasses.MicroMarket

So what's "MICRO_MARKET"? How are you using/creating/mapping this table?

The MicroMarket table is one of the many tables that come with the sample database. The issue is I'm able to create the tables fine (incl MicroMarket) if I'm using EclipseLink but not when I swap in to use Hibernate.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic