I'm trying to retrieve a list of entities from a table with two primary keys which are ids to a foreign key each.
MySQL tables:
Paintings table:
id - int, PK, Auto increment
name - varchar(45)
Pictures table:
id - int, PK, Auto increment
name - varchar(45)
location - varchar(45)
painting_to_picture_link table:
painting_id - int, FK to id in painting
picture_id - int, FK to id in painting
I've set primary key (painting_id, picture_id)
and set them to their foreign keys also as written above.
In Java:
Painting.java
@Entity
@Table(name = "paintings")
public class Painting {
@Id
@GeneratedValue
@Column(name = "id")
private int id;
@Column(name = "name")
private String name;
...
}
Picture.java
@Entity
@Table(name = "pictures")
public class Pictures {
@Id
@GeneratedValue
@Column(name = "id")
private int id;
@Column(name = "name")
private String name;
@Column(name = "location")
private String location;
...
}
PaintingPictureLink.class
public class PaintingPictureLink implements Serializable {
@<SOME ANNOTATION HERE>
private Painting painting;
@<SOME ANNOTATION HERE>
private Picture picture;
...
}
I've seen many examples, but didn't work for me. I've tried putting @Id annotations, @EmbeddedId, etc... non worked. The errors I get are that table isn't mapped, could not determine type for the models, missing @Id annotation... :|
Would appreciate help with querying this table and getting a list of PaintingPictureLink.
Some of the examples I've followed:
Using an Entity (and their Primary Key) as another Entity's Id
Thanks,
Guy