I have the following 5 classes [other attributes and methods have been skipped]
CommonInterface.java
import java.util.Vector;
public class CommonInterface {
public Vector myDescription;
public Vector myPartyPlaceThing;
public Vector myRole;
public Vector myMomentInterval;
}
Description.java
import java.util.Vector;
public class Description {
public Vector myPartyPlaceThing;
public Vector myCommonInterface;
}
PartyPlaceThing.java
import java.util.Vector;
public class PartyPlaceThing {
public Vector myRole;
public Description myDescription;
public Vector myCommonInterface;
}
Role.java
import java.util.Vector;
public class Role {
public Vector myMomentInterval;
public PartyPlaceThing myPartyPlaceThing;
public Vector myCommonInterface;
}
MomentInterval.java
import java.util.Vector;
public class MomentInterval {
public Role myRole;
public Vector myMIDetail;
public Vector myCommonInterface;
}
MIDetail.java
public class MIDetail {
public MomentInterval myMomentInterval;
}
Now I want to persist the data in these classes in a database [mysql] where "tableName in DB == className in java"
I know that such attributes will be included as foreign keys but the problem is how will the tables basically be created?
e.g the table description would contain partyplacething as foreign key. This means that table of partyplacething must exist before table of description can be created. similar is the case with other classes thus creating a deadlock cuz I need tables of "role and description" before I can create partyplacething and so on. the only table that I can successfully create is of MIDetail (right now cuz it is independent).
How should I change my model so that my original relationships are maintained and I can successfully persist data in a database???
Have a look at jpa and check the jpa tutorials.