2017-03-02 10 views
0

私はspring mvcを実行したいときに問題があります。これは私がそれらのファイル APP_USERorg.hibernate.MappingExceptionでエラーが発生しました

@Entity 
@Table(name = "app_user", schema = "spring") 
public class AppUser { 
    private int id; 
    private String nome; 
    private String email; 
    private String password; 
    private String telefone; 
    private String tipo; 
    private byte estado; 
    private byte coordenador; 
    private Set<UserProfile> userProfiles; 

    @Id 
    @Column(name = "id") 
    public int getId() { 
     return id; 
    } 

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

    @Basic 
    @Column(name = "nome") 
    public String getNome() { 
     return nome; 
    } 

    public void setNome(String nome) { 
     this.nome = nome; 
    } 

    @Basic 
    @Column(name = "email") 
    public String getEmail() { 
     return email; 
    } 

    public void setEmail(String email) { 
     this.email = email; 
    } 

    @Basic 
    @Column(name = "password") 
    public String getPassword() { 
     return password; 
    } 

    public void setPassword(String password) { 
     this.password = password; 
    } 

    @Basic 
    @Column(name = "telefone") 
    public String getTelefone() { 
     return telefone; 
    } 

    public void setTelefone(String telefone) { 
     this.telefone = telefone; 
    } 

    @Basic 
    @Column(name = "tipo") 
    public String getTipo() { 
     return tipo; 
    } 

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

    @Basic 
    @Column(name = "estado") 
    public byte getEstado() { 
     return estado; 
    } 

    public void setEstado(byte estado) { 
     this.estado = estado; 
    } 

    @Basic 
    @Column(name = "coordenador") 
    public byte getCoordenador() { 
     return coordenador; 
    } 

    public void setCoordenador(byte coordenador) { 
     this.coordenador = coordenador; 
    } 

    @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) 
    @JoinTable(name = "APP_USER_USER_PROFILE", joinColumns = { 
      @JoinColumn(name = "USER_ID", nullable = false, updatable = false) }, 
      inverseJoinColumns = { @JoinColumn(name = "USER_PROFILE_ID", 
        nullable = false, updatable = false) }) 
    public Set<UserProfile> getUserProfiles() { 
     return userProfiles; 
    } 

    public void setUserProfiles(Set<UserProfile> userProfiles) { 
     this.userProfiles = userProfiles; 
    } 


} 

USER_PROFILE

@Entity 
@Table(name="user_profile") 
public class UserProfile implements Serializable { 

    @Id @GeneratedValue(strategy=GenerationType.AUTO) 
    private Integer id; 

    @Column(name="TYPE", length=15, unique=true, nullable=false) 
    private String type = UserProfileType.USER.getUserProfileType(); 

    public Integer getId() { 
     return id; 
    } 

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

    public String getType() { 
     return type; 
    } 

    public void setType(String type) { 
     this.type = type; 
    } 

    private Set<AppUser> userProfiles; 

    @ManyToMany(fetch = FetchType.LAZY, mappedBy = "userProfiles") 
    public Set<AppUser> getUserProfiles() { 
     return userProfiles; 
    } 

    public void setUserProfiles(Set<AppUser> userProfiles) { 
     this.userProfiles = userProfiles; 
    } 

    @Override 
    public String toString() { 
     return "UserProfile [id=" + id + ", type=" + type + "]"; 
    } 

} 
を持っているデータベースからエンティティを取得した後のモデルは、

My database image

ので、データベースに名前と役割によってユーザを挿入することです

このエラーが発生したtomcatサーバーを実行したとき

Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: user_profile, for columns: [org.hibernate.mapping.Column(userProfiles)] 
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:349) 
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:322) 
at org.hibernate.mapping.Property.isValid(Property.java:241) 
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:496) 
at org.hibernate.mapping.RootClass.validate(RootClass.java:270) 
at org.hibernate.cfg.Configuration.validate(Configuration.java:1360) 
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1851) 
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1930) 

助けてください?

@ManyToMany(fetch = FetchType.LAZY, mappedBy = "userProfiles") 
private Set<AppUser> userProfiles; 

どちらかあなたはフィールドレベルの注釈やメソッドレベルを選択する必要があります。

@ManyToMany(fetch = FetchType.LAZY, mappedBy = "userProfiles") 
    public Set<AppUser> getUserProfiles() { 
     return userProfiles; 
    } 
があなたのフィールドに注釈を移動

答えて

2

あなたは、メソッドレベルの注釈を追加しました。

は、詳細については、この記事を参照してください:Hibernate/JPA - annotating bean methods vs fields

あなたがフィールドに注釈を付ける場合は、Hibernateは を設定し、それらのフィールドを取得するには、フィールド・アクセスを使用します。メソッドに注釈を付けると、hibernateは ゲッターとセッターを使います。 Hibernateは の@Idアノテーションの場所に基づいてアクセスメソッドを選択します。私の知る限り、 とマッチすることはできません。 @Idでフィールドに注釈を付けると、メソッド の注釈は無視されます。

関連する問題