I am new to Java and Hibernate and I am trying to map the following scenario in Hibernate (using annotations).
I am dealing with the following two tables ( related to some ETL type of tasks).
Tasks
|-TaskId
|-SourceDatabase (FK to the Databases table)
|-TargetDatabase (FK to the Databases table)
Databases
|-DatabaseId (PK)
|-TaskId (FK to the Tasks table)
|-Other database details.
Each task has a sourceDatabase and a targetDatabase. Also each Database is related to only one Task.
How can I map to this model in Hibernate using one-to-one mapping.
@Entity
public class Task implements Serializable
{
@Id
int taskId;
//How to map using one-to-one mapping??
Database sourceDB;
//how to map using one-to-one mapping??
Database targetDB;
}
@Entity
public class Database implements Serializable
{
@Id
int databaseId;
//How to map using one-to-one mapping??
Task task;
}
I have removed all unnecessary code from the above code sample.
Thanks in advance!!
As far as I understand, you have 3 separate one-to-one relationships with their respective foreign keys, so you can map them as normal one-to-one relationships: