如何在mysql中保存这样的数据

时间:2011-11-19 21:03:50

标签: java mysql foreign-key-relationship modeling table-relationships

我有以下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]中,其中“ tableName in DB == className in java

我知道这些属性将包含在外键中,但问题是基本上如何创建表格?

例如表格描述将包含partyplacething作为外键。这意味着在创建描述表之前,partyplacething 表必须。类似于其他类的情况因此造成死锁因为我需要“角色和描述”表才能创建partyplacething等等。我能成功创建的唯一表是MIDetail(现在它是独立的)。

我应该如何更改我的模型,以便保持原有的关系,并且我可以成功地将数据保存在数据库中?

1 个答案:

答案 0 :(得分:2)

查看jpa并查看jpa教程。