Question

while following this tutorial:

http://www.objectdb.com/tutorial/jpa/eclipse

I receive the following error:

Exception in thread "main" [ObjectDB 2.5.4_05] javax.persistence.PersistenceException
Type tutorial.model.Point is not found (error 301)
at com.objectdb.jpa.EMImpl.persist(EMImpl.java:437)
at objectdb.tutorial.main.Main.main(Main.java:25)
Caused by: com.objectdb.o.TEX: Type tutorial.model.Point is not found
at com.objectdb.o.MSG.e(MSG.java:107)
at com.objectdb.o.TYM.ay(TYM.java:1017)
at com.objectdb.o.TYM.ap(TYM.java:807)
at com.objectdb.o.TYM.ao(TYM.java:757)
at com.objectdb.o.TYM.at(TYM.java:873)
at com.objectdb.o.TYM.aw(TYM.java:945)
at com.objectdb.o.OBM.bB(OBM.java:371)
at com.objectdb.o.OBM.bB(OBM.java:257)
at com.objectdb.jpa.EMImpl.persist(EMImpl.java:434)
... 1 more
Caused by: java.lang.ClassNotFoundException: tutorial.model.Point
at com.objectdb.o.TYM.findClass(TYM.java:1033)
at com.objectdb.o.ACL.loadClass(ACL.java:131)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at com.objectdb.o.TYM.ay(TYM.java:1013)
... 8 more`

I am looked at this post (Problems searching empty user database with ObjectDB), but for some reason, my instance of EntityManager does not have the member function getMetamodel(). So, I tried to create my own persistence unit which I have below with my code. I still receive the runtime error which seems to occur on em.persist(p) in the first for loop.

package objectdb.tutorial.main;

import javax.persistence.*;

import objectdb.tutorial.model.Point;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        // Open a database connection
        // (create a new database if it doesn't exist yet):
        EntityManagerFactory emf =
            Persistence.createEntityManagerFactory("my-pu");
        EntityManager em = emf.createEntityManager();


        // Store 1000 Point objects in the database:
        em.getTransaction().begin();
        for (int i = 0; i < 1000; i++) {
            Point p = new Point(i, i);
            em.persist(p);
        }
        em.getTransaction().commit();

        // Find the number of Point objects in the database:
        Query q1 = em.createQuery("SELECT COUNT(p) FROM Point p");
        System.out.println("Total Points: " + q1.getSingleResult());

        // Find the average X value:
        Query q2 = em.createQuery("SELECT AVG(p.x) FROM Point p");
        System.out.println("Average X: " + q2.getSingleResult());

        // Retrieve all the Point objects from the database:
        Query query =
            em.createQuery("SELECT p FROM Point p");
        List<Point> results = query.getResultList();
        for (Point p : results) {
            System.out.println(p);
        }

        // Close the database connection:
        em.close();
        emf.close();
    }
}

Entity:

package objectdb.tutorial.model;

import java.io.Serializable;
import javax.persistence.*;

@Entity
public class Point implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id @GeneratedValue
    private long id;

    private int x;
    private int y;

    public Point() {
    }

    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public Long getId() {
        return id;
    }

    public int getX() {
         return x;
    }

    public int getY() {
         return y;
    }

    @Override
    public String toString() {
         return String.format("(%d, %d)", this.x, this.y);
    }
}

persistence.xml :

<?xml version="1.0" encoding="UTF-8" ?>
<persistence 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" version="1.0">

   <persistence-unit name="my-pu">
     <description>My Persistence Unit</description>
     <provider>com.objectdb.jpa.Provider</provider>
     <!-- <mapping-file>META-INF/mappingFile.xml</mapping-file> Not sure what this is-->
     <class>objectdb.tutorial.model.Point</class>
     <properties>
       <property name="javax.persistence.jdbc.url"
                 value="objectdb://localhost/tutorial.odb"/> 
       <property name="javax.persistence.jdbc.user" value="admin"/>
       <property name="javax.persistence.jdbc.password" value="admin"/>

     </properties>
   </persistence-unit>

</persistence>

I appreciate any advice. Thank you.

Was it helpful?

Solution

The error message: "Type tutorial.model.Point is not found" specifies a Point class in a package tutorial.model. Your package name is objectdb.tutorial.model. Probably you had that package name previously, but you moved your package to a new location and name.

Try to delete the database file, since it still includes the class in its previous name (or if you need the data, follow the instructions on ObjectDB website regarding schema change).

If you do not have a getMetamodel method, you may have an old JPA 1.0 jar in your classpath before ObjectDB (which includes the JPA 2.1 jar). You have to fix your classpath to avoid additional issues.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top