Question

Hi Could any one please help me to resolve this exception.Here I have entity class called Person and the thisclass having the instance variable has name and petnames, here petnames I have taken as simple value type that data type is collection and have mapped by using jpa annotation, Please look at my following code and corresponding exception that is generating . And I am facing this exception from so many days.I am struggling to resolve this problem I don not understand where I am going wrong.

Person Class

 private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String name;
    @ElementCollection
    @CollectionTable(name = "petname")
//    @Column(name = "ColumnName")
    private Set<String> petname = new HashSet<String>();

    public Long getId() {
        return id;
    }

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

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setPetname(Set<String> petname) {
        this.petname = petname;
    }

    public Set<String> getPetname() {
        return petname;
    }

    public boolean addPets(String p) {
        return petname.add(p);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Person)) {
            return false;
        }
        Person other = (Person) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.myapp.struts.Person[ id=" + id + " ]";
    }

Excaption

Initial SessionFactory creation failed.org.hibernate.MappingException: Could not determine type for: java.util.Set, for columns: [org.hibernate.mapping.Column(petname)]
Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.myapp.struts.NewHibernateUtil.<clinit>(NewHibernateUtil.java:28)
    at com.myapp.struts.Test.main(Test.java:16)
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Set, for columns: [org.hibernate.mapping.Column(petname)]
    at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
    aJava Result: 1
Was it helpful?

Solution

@CollectionOfElements
@JoinTable(name = "PET", joinColumns = { @JoinColumn(name = "person_id") })
@Column(name = "petname")
private Set<String> petname = new HashSet<String>();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top