Hi,
I have a strange problem because of a legacy database.
In database there are tables like that:
FirstTable
-------------
first_id (Pk)
SecondTable
----------------
second_id (PK)
first_id (
PK/FK from FirstTable)
ThirdTable
-------------
third_id (PK)
second_id (
PK/FK from SecondTable)
first_id (
PK/FK from SecondTable)
FourthTable
--------------
fourth_id (PK)
third_id (
FK from ThirdTable)
second_id(
FK from ThirdTable)
first_id (
FK from ThirdTable)
but i cannot write POJO classes with annotation. I try to use ManyToOne and JoinColumns annotation between "Fourt" and "Third". Then I write PK class for "Third" which include third_id and "Second" POJO object:
Code:
public class Fourt{
@ManyToOne
@JoinColumns({@JoinColumn(name="THIRD_ID", referencedColumnName = "THIRD_ID"),
@JoinColumn(name="SECOND_ID", referencedColumnName = "SECOND_ID"),
@JoinColumn(name="FIRST_ID", referencedColumnName = "FIRST_ID")
})
private Third third;
}
public class Third{
@EmbeddedId
private ThirdPk thirdPk;
...
}
public class ThirdPk{
@Column(name="Third_id")
private Long thirdId;
@ManyToOne
@JoinColumns({@JoinColumn(name="second_id", referencedColumnName = "second_id"),
@JoinColumn(name="first_id", referencedColumnName = "first_id")
})
private Second second;
}
is there another way to model this senario?