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; }