Problem with entities detection

#1

Hi!

I have some problems with ObjectDB. I need to have a persistence.xml with 2 persistence units, one with PostgreSQL, and another with ObjectDB. My problem is with some entities. The only difference is an @Embeddable annotion in a class, and an @Embedded annotation in another.

The problem is that ObjectDB seems to be ignoring the class fields on the persistence.xml file. Entities need to be in the same package when I called my DAO to be stored successfuly. If the entity is in another package, even with the correct import, it says me that the class is not found.

I can´t understand the origin of the problem

 <persistence-unit name="ObjectDB" transaction-type="RESOURCE_LOCAL">
      <provider>com.objectdb.jpa.Provider</provider>
      <class>objectdb.Persona</class>
      <class>objectdb.Asignatura</class>
      <class>objectdb.AsignaturasProfesor</class>
      <class>objectdb.Alumno</class>
      <class>objectdb.Direccion</class>
      <class>objectdb.Profesor</class>
      <class>objectdb.AsignaturasAlumno</class>
    <properties>
      <property name="javax.persistence.jdbc.url" value="$objectdb/db/curso3.odb"/>
      <property name="javax.persistence.jdbc.user" value="admin"/>
      <property name="javax.persistence.jdbc.password" value="admin"/>
    </properties>
  </persistence-unit>

 

If I try to persist an entity of objectdb.Alumno in centroController, the result is:

Caused by: com.objectdb.o._PersistenceException: Type Alumno is not found
    at com.objectdb.o._PersistenceException.a(_PersistenceException.java:45)
    at com.objectdb.o.JPE.d(JPE.java:147)
    at com.objectdb.o.ERR.h(ERR.java:56)
    at com.objectdb.o.OBC.onObjectDBError(OBC.java:1582)
    at com.objectdb.jpa.EMImpl.persist(EMImpl.java:418)
    at model.genericDAO.insert(genericDAO.java:66)
    at controller.centroController.<init>(centroController.java:70)
    at view.MainFormController.<clinit>(MainFormController.java:51)
    ... 29 more
Caused by: com.objectdb.o.TEX: Type Alumno is not found
    at com.objectdb.o.MSG.b(MSG.java:110)
    at com.objectdb.o.TYM.L(TYM.java:1059)
    at com.objectdb.o.TYM.l(TYM.java:839)
    at com.objectdb.o.TYM.R(TYM.java:789)
    at com.objectdb.o.TYM.Q(TYM.java:905)
    at com.objectdb.o.TYM.K(TYM.java:977)
    at com.objectdb.o.OBM.aO(OBM.java:384)
    at com.objectdb.o.OBM.aO(OBM.java:270)
    at com.objectdb.jpa.EMImpl.persist(EMImpl.java:415)
    ... 32 more
Caused by: java.lang.ClassNotFoundException: Alumno
    at com.objectdb.o.TYM.findClass(TYM.java:1075)
    at com.objectdb.o.ACL.loadClass(ACL.java:132)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at com.objectdb.o.TYM.L(TYM.java:1046)
    ... 39 more

But If I move objectdb.Alumno (has an @Embedded Direction object)  and objectdb.Direccion (the @Embeddable) to the same package of centroController, it just works, and locates entities from other packages.

https://i.imgur.com/JXTyHHM.png

 

This is the Entity class Alumno:

package objectdb;

import hibernate.AsignaturasAlumno;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Javier López Medina
 */

@Entity
@Table(name = "alumno")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Alumno_odb.findAll", query = "SELECT a FROM Alumno a")
    , @NamedQuery(name = "Alumno_odb.findByDni", query = "SELECT a FROM Alumno a WHERE a.dni = :dni")
    , @NamedQuery(name = "Alumno_odb.findByNombre", query = "SELECT a FROM Alumno a WHERE a.nombre = :nombre")
    , @NamedQuery(name = "Alumno_odb.findByApellidos", query = "SELECT a FROM Alumno a WHERE a.apellidos = :apellidos")
    , @NamedQuery(name = "Alumno_odb.findByFechaNacimiento", query = "SELECT a FROM Alumno a WHERE a.fecha_nacimiento = :fecha_nacimiento")
    , @NamedQuery(name = "Alumno_odb.findByTelefonos", query = "SELECT a FROM Alumno a WHERE a.telefonos = :telefonos")
    , @NamedQuery(name = "Alumno_odb.findByDireccion", query = "SELECT a FROM Alumno a WHERE a.direccion = :direccion")
    , @NamedQuery(name = "Alumno_odb.findByIdAlumno", query = "SELECT a FROM Alumno a WHERE a.idAlumno = :idAlumno")})
public class Alumno implements Serializable {

    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id_alumno")
    private Long idAlumno;
    @Column(name = "dni")
    private String dni;
    @Column(name = "nombre")
    private String nombre;
    @Column(name = "apellidos")
    private String apellidos;
    @Column(name = "fecha_nacimiento")
    @Temporal(TemporalType.DATE)
    private Date fecha_nacimiento;

    private int[] telefonos;
    
    @Embedded
    private Direccion direccion;
    
    @OneToMany(mappedBy = "idAlumno")
    private List<AsignaturasAlumno> asignaturasAlumnoList;

And this is the Embedded class:

@Embeddable
public class Direccion implements Serializable {
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    String ciudad;
    String calle;
    int numero;
    int codigo_postal;

    public Direccion() {
    }

    public Direccion(String ciudad, String calle, int numero, int codigo_postal) {
        this.ciudad = ciudad;
        this.calle = calle;
        this.numero = numero;
        this.codigo_postal = codigo_postal;
    }
#2

The problem and the context in which it happens are not completely clear.

Please follow the posting instructions and provide a minimal runnable test case (e.g. main + one entity class + one embedded class) that demonstrates the issue.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
#3

I´ve edited the post with more information. The behaviour is so strange, and I don´t know how I can explain it better. It´s the package location the cause of the problem. But I don´t want to have entities on my controller location to make it work. It´s a JavaFX Application.

#4

The best explanation would be to provide a minimal but complete runnable example that shows the exception.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
#5

Ok, after some research and tries, I´ve found the cause. When I put packages inside the entities package, ObjectDB is not able to find the entities. For example, in my case, I have a package named "objectdb" with the entities, and inside this package it´s an "objetdb.model" package. When I have this configuration, ObjectDB throws and exception because it can´t find the entities.

But if I create a new package, for example called "test" with only the entities, classes are found and ObjectDB works correctly. I don´t know if this is a bug of Eclise or ObjectDB, or if this is normal.

The other strange thing is that on the database file, it lists all entities on the project, despite I´ve specified the classes on the persistence.xml (only entities of the "test" package) and "exclude-unlisted-classes" to true for the persistence unit of ObjectDB.

https://i.imgur.com/1Tdq359.png

This is how my persistence.xml looks like now:

<?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="AE4_1PU" transaction-type="RESOURCE_LOCAL">
      <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
      <class>hibernate.Persona</class>
      <class>hibernate.Asignatura</class>
      <class>hibernate.AsignaturasProfesor</class>
      <class>hibernate.Alumno</class>
      <class>hibernate.Profesor</class>
      <class>hibernate.AsignaturasAlumno</class>
      <exclude-unlisted-classes>true</exclude-unlisted-classes>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://192.168.56.101:5432/matriculas3"/>
      <property name="javax.persistence.jdbc.user" value="postgres"/>
      <property name="javax.persistence.jdbc.password" value="qwerty"/>
      <property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>
      <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL94Dialect"/>
    </properties>
  </persistence-unit>
  <persistence-unit name="ObjectDB" transaction-type="RESOURCE_LOCAL">
      <provider>com.objectdb.jpa.Provider</provider>
      <class>test.Persona</class>
      <class>test.Asignatura</class>
      <class>test.AsignaturasProfesor</class>
      <class>test.Alumno</class>
      <class>test.Direccion</class>
      <class>test.Profesor</class>
      <exclude-unlisted-classes>true</exclude-unlisted-classes>
    <properties>
      <property name="javax.persistence.jdbc.url" value="$objectdb/db/curso3.odb"/>
      <property name="javax.persistence.jdbc.user" value="admin"/>
      <property name="javax.persistence.jdbc.password" value="admin"/>
    </properties>
  </persistence-unit>
</persistence>

 

#6

ObjectDB uses the com.objectdb and objectdb prefixes for internal purposes, so maybe changing the package name to test, etc. solves the issue, regardless of where the entity classes are defined. Note that you are not expected to use the names com.objectdb and objectdb for your own packages.

Please follow the posting instructions and for additional questions create new threads, one thread per issue with a title that matches the question.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login