Hi,we're getting some dificult to map this scenario:
Code:
@Entity
class ScrapBook{
@Id@GeneratedValue(strategy=GenerationType.IDENTITY)
int id;
@OneToMany(mappedBy="scrapBook", fetch=FetchType.LAZY)
List<PageSet> pageSet;
}
@Entity
class PageSet{
@Id@GeneratedValue(strategy=GenerationType.IDENTITY)
int id;
@ManyToOne( cascade={CascadeType.ALL})
ScrapBook scrapBook;
@OneToOne@JoinColumn(name="id", unique=false, nullable=true)
LandscapePage landscapePage;
@OneToOne@JoinColumn(name="id", unique=false, nullable=true)
PortraitPage portraitPage;
}
@MappedSuperclass
class Page{
@Id@GeneratedValue(strategy=GenerationType.IDENTITY)
id;
@ManyToOne( cascade={CascadeType.ALL})
PageSet pageSet;
@OneToMany(mappedBy="page", fetch=FetchType.LAZY)
List<Photo> photos;
}
@Entity
class LandscapePage extends Page{}
@Entity
class PortraitPage extends Page{}
@Entity
class Photo{
@Id@GeneratedValue(strategy=GenerationType.IDENTITY)
int id;
@ManyToOne( cascade={CascadeType.ALL})
Page page;
}
How can we do a reverse mapping Photo->(LandscapePage/PortraitPage) ?
We would like to mantain all pages(landscape an portrait) on a single table.
Thanks in advance