ObjectDB ObjectDB

Failing in embedded mode, correct javax.persistance?

#1

I'm trying to run the tutorial example as given in the tutorial on ObjectDB's net pages. I am using NetBeans IDE 13 with Java 17.0.2 on Windows 11and with ant. My ObjectDB is version 2.8.7.

Q 1)
The tutorial is supposed to run embedded. If the file given does not exist, it should be created. Instead I get the error "No Persistence provider for EntityManager named objectdb:punkter.odb" that many have reported. Answers I find invariably focus on the "persistence.xml" and where it should be stored, contents etc. Since I am running the program in embedded mode, this file should not be necessary. Can anyone see the problem? Could the problem be the javax.persistance version?

package tutorial;
import javax.persistence.*;
import java.util.*; 
public class Main {
    public static void main(String[] args) {
        EntityManagerFactory emf = 
            Persistence.createEntityManagerFactory("objectdb:punkter.odb");
        EntityManager em = emf.createEntityManager();. the code continues as in the tutorial…

(I should mention that I have tried running NetBeans in admin mode, and I have tried creating an empty "punkter.odb" file in the map holding the java-files as well as the map containing the class-files. All in case NetBeans have problem creating the file.)

Q 2)
Several sources are adamant that the program class should be called "Main". I fail to see the significance of that. Can you please explain if this is really necessary and if so, why?

Q 3)
I have tried several versions of "javax.persistence". When I use "javax.persistence_1.99.0.jar" I get an error using TypedQuery. I have therefore tried "javax.persistence-2.2.0-release.jar". Then TypedQuery is recognized but the "No Persistence provider" error persist. Can you tell me what version of javax.persistence I should use and where I can find it?

edit
delete
#2

It seems to be a classpath issue. Try the following:

  1. Download the last ObjectDB version.
  2. Include objectdb.jar from that zip file in your classpath.
  3. Remove any other JPA / ObjectDB jar files from the classpath.

Alternatively, include in the classpath only objectdb-jee.jar + javax.persistence-2.2.0-release.jar.

ObjectDB Support
edit
delete
#3

Thank you, thank you, thank you...

I checked and found I had no classpath set. I moved the two jar-files in question to my project directory and it worked fine.

I then moved them to the Java/jdk-directory and got problems with the log-file (residing in objectdb.home which is then protected by Windows). I am asking a separate question on this problem.

Again thanks!

edit
delete

Reply

To post on this website please sign in.