I am trying Spring data jpa implementation using CrudRepository. Below is my Entity Class
public class User {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id = null;
@OneToMany
@ElementCollection
@CollectionTable(name="photoUrls")
@Valid
private List<String> photoUrls = new ArrayList<String>();
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public List<String> getPhotoUrls() {
return photoUrls;
}
public void setPhotoUrls(List<String> photoUrls) {
this.photoUrls = photoUrls;
}
}
And have a repository as below,
public interface UserRepository extends CrudRepository<User, Long>{
}
And trying to use h2 database for local testing
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
And from the CommandLineRunner calling the save method of the UserRepository, but getting below error,
Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: model.User.photoUrls[java.lang.String] at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1191) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final] at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:794) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]