Boa tarde,
Estou iniciando com Hibernate e estou tendo problema para mapear um relacionamento @OneToMany.
Segue as classes abaixo:
//CLASSE Locatario-------------------------------------------------------
package persistencia;
import java.util.Collection;
import javax.persistence.*;
import java.io.Serializable;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
@Entity
public class Locatario implements Serializable
{
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator =“genCodLocatario”)
@SequenceGenerator(name =“genCodLocatario”, sequenceName =“genCodLocatario”, allocationSize=1)
private int codLocatario;
private String nome;
private String cpf_cnpj;
private String tipo;
@OneToMany(mappedBy =“locatario”, fetch = FetchType.LAZY)
@Cascade(CascadeType.ALL)
private Collection<TelefoneLocatario> telefones;
//Métodos getters e setters
}
//CLASSE TelefoneLocatario------------------------------------------------------
package persistencia;
import javax.persistence.*;
import java.io.Serializable;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
@Embeddable
public class TelefoneLocatario implements Serializable
{
private String telefone;
private String tipo;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name="codLocatario", insertable=true, updatable=true)
@Fetch(FetchMode.JOIN)
@Cascade(CascadeType.SAVE_UPDATE)
private Locatario locatario;
//Métodos getters e setters
}
o arquivo hibernate.cfg.xml está assim:
<?xml version=“1.0” encoding=“utf-8”?>
<!DOCTYPE hibernate-configuration PUBLIC
“-//Hibernate/Hibernate Configuration DTD 3.0//EN”
“http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd”>
<hibernate-configuration>
<session-factory>
<!-- properties -->
<property name="connection.driver_class"> org.firebirdsql.jdbc.FBDriver </property>
<property name="connection.url"> jdbc:firebirdsql:localhost/3050:/usr/SistemaAlugueis/alugueis.gdb </property>
<property name="dialect"> org.hibernate.dialect.FirebirdDialect </property>
<property name="show_sql">true</property>
<property name="connection.username">SYSDBA</property>
<property name="connection.password">masterkey</property>
<property name="connection.pool_size">10</property>
<!-- mapping classes -->
<mapping class="persistencia.Locatario"/>
<mapping class="persistencia.TelefoneLocatario"/>
</session-factory>
</hibernate-configuration>
Está aparecendo a seguinte mensagem de erro:
Exception in thread “AWT-EventQueue-0” org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: persistencia.Locatario.telefones[persistencia.TelefoneLocatario]
at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1033)
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:576)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:517)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1130)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:316)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
O que estou fazendo de errado?