Error in Eclipse: Could not locate getter for property

0

You see, I have 2 classes, a call NIF, which takes the ID of one person, and another call Secure, with the data of a person. These classes are related so that NIF is a component of Insurance.

Table NIF:

package es.makigas.hibernate.modelo;

import java.io.Serializable;

public class NIF implements Serializable{
    private static final long serialVersionUID = 1L;

    String nif;

    public NIF() {}

    public NIF(String nif) {
        this.nif = nif;
    }

    public String getNif() {
        return nif;
    }

    public void setNif(String nif) {
        this.nif = nif;
    }
}

Safe Table:

package es.makigas.hibernate.modelo;

import java.io.Serializable;

public class Seguro implements Serializable{
private static final long serialVersionUID = 1L;

int id;

NIF nif;

String nombre;

String ape;



public Seguro() {}



public Seguro(NIF nif, String nombre, String ape) {
    this.nif = nif;
    this.nombre = nombre;
    this.ape = ape;
}



public int getId() {
    return id;
}



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



public NIF getNif() {
    return nif;
}



public void setNif(NIF nif) {
    this.nif = nif;
}



public String getNombre() {
    return nombre;
}



public void setNombre(String nombre) {
    this.nombre = nombre;
}



public String getApe() {
    return ape;
}



public void setApe(String ape) {
    this.ape = ape;
}



@Override
public String toString() {
    return "Seguro [id=" + id + ", nif=" + nif + ", nombre=" + nombre + ", ape=" + ape + "]";
}
}

And to handle this relationship I have the file Seguro.hbm.xml:

<?xml version="1.0" encoding="UTF-8"?>

<hibernate-mapping>
  <class name="es.makigas.hibernate.modelo.Seguro" >
    <id column="Id" name="id" type="integer">
        <generator class="increment" />
    </id>
    <property name="nombre" />
    <property name="ape" />

    <component name="NIF">
        <property name="nif" />
    </component>

  </class>
</hibernate-mapping>

And all this is proven here:

package tests;

import java.text.ParseException;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import es.makigas.hibernate.modelo.NIF;
import es.makigas.hibernate.modelo.Seguro;

public class TestSeguros{
    private static EntityManagerFactory emf=Persistence.createEntityManagerFactory("Persistencia");
    private static EntityManager manager=emf.createEntityManager();

    public static void main(String[] args) throws ParseException{
        Seguro seg1 = new Seguro(new NIF("36254784E"), "Rosa", "Ramirez");
        Seguro seg2 = new Seguro(new NIF("47653952Q"), "Carlos", "Jimenez");
        Seguro seg3 = new Seguro(new NIF("59044376G"), "Pedro", "Berdoza");

        manager.getTransaction().begin();

        manager.persist(seg1);
        manager.persist(seg2);
        manager.persist(seg3);

        manager.getTransaction().commit();

        @SuppressWarnings("unchecked")
        List<Seguro> s=manager.createQuery("FROM Seguro").getResultList();

        for(Seguro seg:s)
            System.out.println(seg.toString());

        manager.close();
    }
}

And after all this I see myself with the following:

Does anyone know what I'm doing wrong?

    
asked by Miguel Alparez 27.02.2018 в 20:20
source

1 answer

0

I have found the solution. It was a matter of putting this in the hbm file.

<component name="Nif">
        <property name="nif" />
    </component>
    
answered by 27.02.2018 в 20:33