2016-02-12 2 views
2

У меня проблема с тем, что Hibernate не может определить тип для коллекции в таблице Region. Я пытаюсь создать внешний ключ таблицы Actels через отношения «один ко многим». регион может иметь много actels.org.hibernate.MappingException: Не удалось определить тип для: java.util.Collection, в таблице

Подробно:

Ошибка я получаю это:

Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Collection, at table: Region, for columns: [org.hibernate.mapping.Column(collection_actels)] 
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:316) 
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:294) 
at org.hibernate.mapping.Property.isValid(Property.java:238) 
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:469) 
at org.hibernate.mapping.RootClass.validate(RootClass.java:270) 
at org.hibernate.cfg.Configuration.validate(Configuration.java:1294) 
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1742) 
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:94) 
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905) 
... 20 more 

Region.java:

package com.springJPA.domain; 

import java.io.Serializable; 
import java.lang.String; 
import java.util.Collection; 

import javax.persistence.*; 

import com.springJPA.domain.Actels; 

/** 
* Entity implementation class for Entity: Reseau 
* 
*/ 
@Entity 

public class Region implements Serializable { 


    private int id_region; 
    private String region; 
    private String ville; 
    private int codep; 
    private int num_region; 
    private int num_ville; 

    private Collection<Actels> collection_actels; 

    private static final long serialVersionUID = 1L; 
    private Collection<Actels> actels; 

    public Region() { 
     super(); 
    } 

    @Id 
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "id_Sequence_region") 
    @SequenceGenerator(name = "id_Sequence_region", sequenceName = "ID_SEQ_REGION") 
    public int getId_region() { 
     return id_region; 
    } 
    public void setId_region(int id_region) { 
     this.id_region = id_region; 
    } 
    public String getRegion() { 
     return this.region; 
    } 

    public void setRegion(String region) { 
     this.region = region; 
    } 
    public String getVille() { 
     return this.ville; 
    } 

    public void setVille(String ville) { 
     this.ville = ville; 
    } 
    public int getCodep() { 
     return this.codep; 
    } 

    public void setCodep(int codep) { 
     this.codep = codep; 
    } 

    public Collection<Actels> getCollection_actels() { 
     return collection_actels; 
    } 

    public void setCollection_actels(Collection<Actels> collection_actels) { 
     this.collection_actels = collection_actels; 
    } 

    public int getNum_region() { 
     return num_region; 
    } 

    public void setNum_region(int num_region) { 
     this.num_region = num_region; 
    } 

    public int getNum_ville() { 
     return num_ville; 
    } 

    public void setNum_ville(int num_ville) { 
     this.num_ville = num_ville; 
    } 

    @OneToMany 
    @JoinColumn(name = "Region_id_region", referencedColumnName = "id_region") 
    public Collection<Actels> getActels() { 
     return actels; 
    } 

    public void setActels(Collection<Actels> param) { 
     this.actels = param; 
    } 


} 

Actels.java:

package com.springJPA.domain; 

import java.io.Serializable; 

import javax.persistence.Entity; 
import javax.persistence.GeneratedValue; 
import javax.persistence.GenerationType; 
import javax.persistence.Id; 
import javax.persistence.SequenceGenerator; 

/** 
* Entity implementation class for Entity: Actels 
* 
*/ 
@Entity 

public class Actels implements Serializable { 

    private int id_actels; 
    private String nomActels; 
    private int num_actel; 

    private Region region; 

    private static final long serialVersionUID = 1L; 
    public Actels() { 
     super(); 
    } 

    @Id 
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "id_Sequence_actels") 
    @SequenceGenerator(name = "id_Sequence_actels", sequenceName = "ID_SEQ_ACTELS") 
    public int getId_actels() { 
     return id_actels; 
    } 
    public void setId_actels(int id_actels) { 
     this.id_actels = id_actels; 
    } 

    public String getNomActels() { 
     return this.nomActels; 
    } 

    public void setNomActels(String nomActels) { 
     this.nomActels = nomActels; 
    } 

    public Region getRegion() { 
     return region; 
    } 

    public void setRegion(Region region) { 
     this.region = region; 
    } 

    public int getNum_actel() { 
     return num_actel; 
    } 

    public void setNum_actel(int num_actel) { 
     this.num_actel = num_actel; 
    } 


} 

ответ

1

Put любой JPA annotation над каждым полем вместо getter собственности:

@SequenceGenerator(name = "id_Sequence_actels", sequenceName = "ID_SEQ_ACTELS") 
    private int id_actels; 

И:

@JoinColumn(name = "Region_id_region", referencedColumnName = "id_region") 
private Collection<Actels> actels; 
0
@Column 
@ElementCollection(targetClass=String.class) 
public Set<String> getOptions() { 
    return options; 
} 

ИЛИ

@OneToMany(cascade=CascadeType.ALL, fetch = FetchType.EAGER) 
@JoinColumn(name = "....") 
public Set<String> getOptions() { 
    return options; 
} 
+0

Добавьте описание к нему ..... – piyushj

Смежные вопросы