1

我有两节课:

@Entity   
@Table(name = "movies")  
public class Movie implements Serializable {  
    @Id  
    private int movieID;  
    private String name;  
    private int year;  
    private Genre genre;  
    //constructor, getters, setters  
}  

@Entity  
@Table(name = "genres")  
public class Genreimplements Serializable {  
    @Id  
    private int genreID;  
    private String name;  
    //constructor, getters, setters  
}  

数据库表是(简化,因此您只看到字段):
电影(int movieID,文本名称,int year,intgenreID)
流派(intgenreID,文本名称)

如何将genreID 字段映射到Movie 类中的流派对象(最好使用注释)?

(我正在使用 jsf 和休眠)

4

1 回答 1

1

将其插入 Movie.class

@OneToOne(targetEntity = Genre.class)
@JoinColumn(name="GENRE_FK_COLUMN_NAME_IN_MOVIE_TABLE", referencedColumnName = "ID_OF_GENRE_TABLE")
private Genre genre;
于 2013-09-23T20:58:00.577 回答