Unexpected exception (error 990)

#1

When i run my code, the console returns to me the following error:

Exception in thread "main" [ObjectDB 2.8.7] Unexpected exception (Error 990)
  Generated by Java HotSpot(TM) 64-Bit Server VM 15.0.2 (on Windows 10 10.0).
Please report this error on http://www.objectdb.com/issue/new
com.objectdb.o.InternalException: null
com.objectdb.o.InternalException
    at com.objectdb.o.VUT.i(VUT.java:250)
    at com.objectdb.o.VUT.i(VUT.java:156)
    at com.objectdb.o.UMR.w(UMR.java:462)
    at com.objectdb.o.UMR.f(UMR.java:405)
    at com.objectdb.o.UML.k(UML.java:487)
    at com.objectdb.o.MMM.j(MMM.java:890)
    at com.objectdb.o.OBM.aQ(OBM.java:434)
    at com.objectdb.o.OBM.aQ(OBM.java:293)
    at com.objectdb.jpa.EMImpl.persist(EMImpl.java:421)
    at e1t13.E1T13.main(E1T13.java:41)

//This is the code:

//CLASS PEOPLE AND WORKER

@Embeddable public class Persona implements Serializable {
    
    protected String DNI;
    protected String nombre;

    public String getDNI() {
        return DNI;
    }

    public void setDNI(String DNI) {
        this.DNI = DNI;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }    
    Persona(){
        Scanner entrada = new Scanner(System.in);
        System.out.println("¿Cuál es tu nombre?");
        this.nombre = entrada.next();
        System.out.println("¿Cuál es tu DNI?");
        this.DNI = entrada.next();
    }
    
}

class Trabajador extends Persona implements Serializable{
    
    private Integer numt;
    Scanner entrada = new Scanner(System.in);
    public Integer getNumt() {
        return numt;
    }

    public void setNumt(Integer numt) {
        this.numt = numt;
    }
    
    Trabajador(){
        
        super();
        System.out.println("¿Cuál es su numero de trabajador?");
        this.numt = entrada.nextInt();
        
    }
}


@Entity public class Vehiculo implements Serializable {
    @Id     
    Scanner entrada = new Scanner(System.in);
    
    protected int id;
    protected String matricula;
    protected String fmat;
    @Embedded private Persona piloto;

    public Integer getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

//CLASS VEHICLE AND CAR    
    Vehiculo(){ 
        
        System.out.println("¿Cuál es el id de su vehículo");
        this.id = entrada.nextInt();
        System.out.println("¿Cuál es su matrícula?");
        this.matricula = entrada.next();
        System.out.println("¿Cual es su fecha de matriculación?");
        this.fmat = entrada.next();
        
            System.out.println("¿Trabaja con nosotros?");
            String choose = entrada.next();
            if(choose.equalsIgnoreCase("no")){
                Persona p1 = new Persona();
                this.piloto = p1;
            } else{
                       Trabajador t1 = new Trabajador(); 
                       this.piloto = t1;
                        }
    }
}

@Entity class Coche extends Vehiculo implements Serializable{
    Scanner entrada = new Scanner(System.in);
    public String getEnergia() {
        return energia;
    }

    public void setEnergia(String energia) {
        this.energia = energia;
    }
    private String energia;
    
    Coche(){
        super();
        System.out.println("¿Qué tipo de energía necesita tu coche?");
        this.energia = entrada.next();
    }
    
}


//MAIN

public static void main(String[] args) {
        Scanner entrada = new Scanner(System.in);

        EntityManagerFactory emf;
        emf = Persistence.createEntityManagerFactory("C:\\NetBeansProjects\\objectdb-2.8.7\\db\\VehiculoPersona.odb");
        EntityManager em;
        em = emf.createEntityManager();

        for (int i = 0; i < 4; i++) {
            System.out.println("¿Su vehículo es un coche?");
            String choose = entrada.nextLine();
            if (choose.equalsIgnoreCase("no")) {
                em.getTransaction().begin();
                Vehiculo v1 = new Vehiculo();
                em.persist(v1);
                em.getTransaction().commit();
            } else {
                em.getTransaction().begin();
                Coche c1 = new Coche();
                em.persist(c1);
                em.getTransaction().commit();
            }

        }
        
        em.close();
        emf.close();
    }

}
#2

Thank you for this report.  A friendly error message is needed in this case, but apparently the issue is using non-persistable fields ("Scanner entrada") in your persistable classes. Try defining these fields as transient (add the transient modifier).

In addition, note that Trabajador extends a persistable type but is not defined as embeddable/entity.

ObjectDB Support
#3

Yas! I did the changes that you pointed out and it works! Thank you so much

Reply