I have two tables, a user
table and a user_avatar
table. For each user, there are 3 records in the user_avatar
table, for 3 sizes of avatars (large, medium, small).
The user_avatar
table has a userId
column which refers to the User.id
field to specify to which user an avatar belongs to.
Here's my UserAvatar
class:
@Entity @Table(name = "user_avatar")
public class UserAvatar
{
@Id @GeneratedValue
private long id;
@ManyToOne
@JoinColumn(name = "userId")
private User user;
@Enumerated(EnumType.STRING)
private AvatarSize size;
private String file;
private String s3Key;
@Override
public String toString()
{
return size + " " + file;
}
}
And here's how I'm referring to it in the `user
@Entity
public class User
{
@Id @GeneratedValue
public Long id;
@OneToMany
@JoinColumn(name = "id")
@OrderColumn(name = "id")
public UserAvatar[] avatar; //declared array as there'd be at least 3 records
}
When I run this code, I get the error:
Repeated column in mapping for collection: com.xxx.User.avatar column: id
What am I doing wrong?