如何将此类数据持久化到mysql中
我有以下 5 个类 [其他属性和方法已被跳过]
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;
}
现在我想将这些类中的数据保存在数据库 [mysql] 中,其中“DB 中的tableName = = 中的类名java”
我知道这些属性将作为外键包含在内,但问题是基本上如何创建表?
例如表描述将包含 partyplacething 作为外键。这意味着在创建描述表之前,partyplacething 表必须存在。其他类的情况也类似,因此造成了僵局,因为我需要“角色和描述”表,然后才能创建 partyplacething 等。我可以成功创建的唯一表是 MIDetail 表(现在因为它是独立的)。
我应该如何更改我的模型,以便维持我原来的关系,并且我可以成功地将数据保存在数据库中???
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???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 jpa 并查看 jpa 教程。
Have a look at jpa and check the jpa tutorials.