简体   繁体   English

如何在mysql中持久保存此类数据

[英]How to persist such data in mysql

I have the following 5 classes [other attributes and methods have been skipped] 我有以下5个课程[其他属性和方法已跳过]

CommonInterface.java CommonInterface.java

    import java.util.Vector;

    public class CommonInterface {

        public Vector  myDescription;
        public Vector  myPartyPlaceThing;
        public Vector  myRole;
        public Vector  myMomentInterval;

    }

Description.java Description.java

    import java.util.Vector;

    public class Description {

     public Vector  myPartyPlaceThing;
        public Vector  myCommonInterface;

    }

PartyPlaceThing.java PartyPlaceThing.java

    import java.util.Vector;

    public class PartyPlaceThing {

      public Vector  myRole;
        public Description myDescription;
        public Vector  myCommonInterface;

    }

Role.java 角色.java

    import java.util.Vector;

    public class Role {

    public Vector  myMomentInterval;
        public PartyPlaceThing myPartyPlaceThing;
        public Vector  myCommonInterface;

    }

MomentInterval.java MomentInterval.java

    import java.util.Vector;

    public class MomentInterval {

    public Role myRole;
    public Vector  myMIDetail;
    public Vector  myCommonInterface;

    }

MIDetail.java 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 " 现在,我想将这些类中的数据保存在数据库[mysql]中,其中“ DB中的tableName = java中的className

I know that such attributes will be included as foreign keys but the problem is how will the tables basically be created? 我知道这样的属性将作为外键包括在内,但问题是基本上将如何创建表?

eg the table description would contain partyplacething as foreign key. 例如 ,表说明将包含partyplacething作为外键。 This means that table of partyplacething must exist before table of description can be created. 这意味着在创建描述表之前,partyplacething表必须存在。 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. 其他类也是如此,因此创建了死锁,因为在创建partyplacething之前,我需要“角色和描述”表。 the only table that I can successfully create is of MIDetail (right now cuz it is independent). 我唯一可以成功创建的表是MIDetail(现在,因为它是独立的)。

How should I change my model so that my original relationships are maintained and I can successfully persist data in a database??? 我应该如何更改模型,以保持原始关系,并可以成功地将数据持久存储在数据库中???

看看jpa并查看jpa教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM