2016-11-24 5 views
-1

私はそれが次のエラーを与えるContactクラスの電話機で電話をマップしよう:hibernateを使ってクラス属性をマッピングするには?

Initial creation of the SessionFactory object failed. Error: org.hibernate.MappingException: Could not determine type for: com.livro.capitulo3.crudannotations.Telephone, at table: contact, for columns: [org.hibernate.mapping.Column (numPhone)] Error closing insert operation. Message: null java.lang.ExceptionInInitializerError The mapping class is as follows:

//クラスContato

package com.livro.capitulo3.crudannotations; 

import java.sql.Date; 

import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.GeneratedValue; 
import javax.persistence.Id; 
import javax.persistence.ManyToOne; 
import javax.persistence.OneToMany; 
import javax.persistence.Table; 

import org.hibernate.annotations.ManyToAny; 

@Entity 
@Table(name = "contato") 
public class ContatoAnnotations { 

    @Id 
    @GeneratedValue 
    @Column(name = "codigo") 
    private Integer codigo; 

    @Column(name = "nome", length = 50, nullable = true) 
    private String nome; 

    @Column(name = "telefone", length = 50, nullable = true) 
    private String telefone; 

    @Column(name = "email", length = 50, nullable = true) 
    private String email; 

    @Column(name = "dt_cad", nullable = true) 
    private Date  dataCadastro; 

    @Column(name = "obs", nullable = true) 
    private String observacao; 


    //Como ficaria a annotation aqui???? Só vou persistir esta tabela 
    @OneToMany 
    private Telefone numTelefone; 
    ... 
    //Getters e Setters 

} 

//クラスTelefone:

package com.livro.capitulo3.crudannotations; 

import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.GeneratedValue; 
import javax.persistence.Id; 
import javax.persistence.ManyToOne; 
import javax.persistence.OneToMany; 
import javax.persistence.Table; 

@Entity 
@Table(name = "contato") 
public class Telefone { 
    @Id 
    @GeneratedValue 
    @Column(name = "numero") 
    private String numero; 
    @Column(name = "tipo") 
    private String tipo; 

    public String getNumero() { 
     return numero; 
    } 

    public void setNumero(String numero) { 
     this.numero = numero; 
    } 

    public String getTipo() { 
     return tipo; 
    } 

    public void setTipo(String tipo) { 
     this.tipo = tipo; 
    } 

} 

このマッピングの仕方はわかりません。助けて!ありがとう!!!

+0

英語で質問してください。 – DimaSan

+0

すみません!一定!急いで! – Deb

+0

両方のエンティティを同じテーブル 'contato'にマップするのはなぜですか?それは2つの異なるテーブルでなければなりません。 – DimaSan

答えて

0

あなたが@OneToManyアノテーションを使用している場合、それはListまたはSetのようないくつかのコレクションである必要があります。

@OneToMany(cascade = CascadeType.ALL, mappedBy = "contacto") 
private List<Telefone> numTelefone = new ArrayList<>(); 

またTelephoneエンティティのテーブル名を変更し、それがcontactoよりも異なっている必要があります:

@Entity 
@Table(name = "tel") 
public class Telefone {...} 
+0

クラスの電話機をマップできませんか? – Deb

関連する問題