'Getting a org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: Authors after using @ElementCollection
I am trying to persist collection of string for an Entity. To be more specific here is my Entity:
@Entity
@Table(name = "AUTHOR")
public class Author{
//Other fields associated with author
@ElementCollection
@CollectionTable(name = "AUTHOR_PHONE_NUMBER", joinColumns = @JoinColumn(name = "author_id"))
@Column(name="phone_number")
private Set<String> phoneNumbers;
//Constructors
//Getters & Setters
}
However, when I build and run the code, I am getting following exceptions:
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: AUTHOR for columns: [org.hibernate.mapping.Column(phone_number)]
I am seeing many questions similar to this on this platform but all those involve OneToMany mapping to persist collections.
Solution 1:[1]
The list phoneNumbers should be @OneToMany, @ManyToMany (this depends from AUTHOR_PHONE_NUMBER table) annotation, replacing @CollectionTable.
the configuration must be same with @JoinColumn annotation.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Rodrigo Rocha |
