ManyToMany Hibernate error

2
Hello, I have a% bidirectional% co_related relationship between the class @ManyToMany and Pessoa , where for these, I have the tables in the database for person, address and the table for the relationship between them, Endereço .

It happens that when I query in HQL to test the relationship of the classes, doing the select of the Person class presents the following error.

org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: model.Endereco.pessoas[model.Pessoa]
at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1134)
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:793)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:728)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:70)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1695)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1424)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)

Classes declared in cfg.xml

<mapping class="model.Endereco"/>
<mapping class="model.Pessoa"/>

The annotations are as follows:

@Entity
@Table(name = "tab_pessoa")
public class Pessoa implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id_pes")
    private int id;

    @ManyToMany(targetEntity = Endereco.class, fetch = FetchType.LAZY)
    @JoinTable(name = "rel_pes_endereco",  
            joinColumns = { @JoinColumn(name = "id_pes") }, 
            inverseJoinColumns = { @JoinColumn(name = "id_endereco") } )
    private List<Endereco> enderecos;


    //Get Set
}
@Entity
@Table(name = "tab_endereco")
public class Endereco implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id_endereco")
    private int id;

    @ManyToMany(mappedBy = "enderecos", targetEntity = Pessoa.class)
    private List<Pessoa> pessoas;  

    //Get e Set
}

I started to use the tool recently, I looked at some related problems and the documentation and I was creating according, I made this same mapping in several other ways, but I always get the same message.

Could someone help?

Thank you in advance.

    
asked by anonymous 11.01.2018 / 21:51

0 answers