Hello All,
I have a relationship I need to model. I wanted to have a join table with 3 IDs and ManyToOne and OneToMany annotations.
Code:
create table folder(
id primary key
);
create table document(
id primary key
);
create table type(
id primary key
);
create table folder_document(
folder_id references folder(id),
type_id references type(id), //the same document can be of different types in different folders.
document_id references document(id),
);
I'd like to model:
Code:
public Class Folder(
@ManyToOne //technically, this is a OneToMany in the DB, but logic is enforced by code.
@JoinTable(name = "folder_document")
@SomeDiscriminatorColumn(column="type_id", value="foo")
private Document foo
@OneToMany
@JoinTable(name = "folder_document")
@SomeDiscriminatorColumn(column="type_id", value="bar")
private List<Document> foo
);
Is there some way of doing it? I have a few relationships that are based on 3 columns.
I know I can do read only JPA objects by creating views and using them as the join table, but I'd have to create the DB rows outside of JPA as JPA wouldn't know to create a row in folder_document with a type value of "foo".
If this is just not doable in JPA, what is the best way to model this manually? Is there a way of creating a manual mapping of the relationship that will allow users to otherwise use JPA functionality?
Thanks in advance,
Steven