如何将此类数据持久化到mysql中

发布于 2024-12-17 04:27:30 字数 1861 浏览 1 评论 0原文

我有以下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月流歌 2024-12-24 04:27:30

查看 jpa 并查看 jpa 教程。

Have a look at jpa and check the jpa tutorials.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文