collection element mapping has wrong number of columns for column of type Map

Viewed 704

I m trying to make a table with a column of type Map, but getting error "Collection element mapping has wrong number of columns". Below is the model for reference :

@Entity
@Table(name = "media")
public class Media {

@NotBlank
private String url;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;

@ElementCollection
private Set<String> textList = new HashSet<String>();

@ElementCollection
private Set<String> tagList = new HashSet<String>();

private String textListText;
private String tagListText;

@ElementCollection
@CollectionTable(name="media_meta_data",joinColumns=@JoinColumn(name="media_id"))
@MapKeyColumn(name="meta_key")
@Column(name="meta_value")
Map<String, Object> metaData= new HashMap<>();

public Map<String, Object> getMetaData() {
    return this.metaData;
}

public void setMetaData(Map<String, Object> metaData) {
    this.metaData = metaData;
}
}
1 Answers

i think you want a related table with a foreign key, so you can use CollectionTable .. enter image description here

my code create a table name "tbl_phone" ...

enter image description here

Related