【发布时间】:2013-05-08 18:46:01
【问题描述】:
我最近建模了一个基本上涉及关联的 UML 图。假设代码是:
public class Seller{
private int idSeller;
private String name;
private String passw;
private List<Phone> phones = new ArrayList<Phone>();
public Seller() {
}
public Seller(int idSeller, String name, String passw, List<Phone>phones) {
super();
this.idSeller = idSeller;
this.name = name;
this.passw = passw;
this.phones = phones;
}
//getters and setters
}
和
public class Phone {
private int idPhone;
private String description;
private String number; //will have some chars in it
public Phone() {
}
public Phone(int idPhone, String description, String number) {
super();
this.idPhone = idPhone;
this.description = description;
this.number = number;
}
//getters and setters
}
我不想限制卖家可以拥有的手机数量,而且这只是我整个代码的摘录。
现在,我需要创建我的 SQLite 数据库并将数据插入其中,但我对如何表示从 UML 到数据库的关联有点困惑。
如果我不使用 OO,我会在 Phone 表中放置一个外键,指代拥有手机的卖家 id,但 OO 的概念让我怀疑这是否是正确的做法。
我对 UML 有很好的理解,但这是我第一次尝试实现 UML 图并从数据库加载数据。有人可以帮我说一下正确的方法吗?
【问题讨论】:
-
两次投反对票,没有任何解释。谁能告诉我怎么了?
-
数据库表之间需要一个外键。您刚刚体验了对象-关系阻抗en.wikipedia.org/wiki/Object-relational_impedance_mismatch
-
我喜欢“对象-关系阻抗”这个术语,它准确地代表了发生在我身上的事情。谢谢。
标签: sqlite foreign-keys uml