English 中文(简体)
自愿:在遗产表中绘制一至多条关系图,该表将一栏作为一到许多关系中的一行。
原标题:Hibernate: Mapping a one to many relationship on a legacy table that uses columns as rows for the one to many relationship

我正在就我无法改变的数据库编写一份表格。 该表列有用户联系清单,例如电子邮件、面板、tw等。 每个联系人都有一栏。 因此,会议认为:

USER {
    user_id,
    email,
    facebook,
    twitter,
    ...
}

我需要将这一数据库与使用春天/西伯利亚的申请联系起来。 这一应用预期用户的“一对一”关系:

User {
    user_id,
    ...
}
Contacts {
    contact_id,
    user_id,
    type,
    value
}

我如何利用秘密地图实现这一转变?

问题回答

只字不提一个实体的<代码>Contact,但使之成为一个POJO,并在用户的<代码>getContacts方法中退回一份POJOs清单:

public List<Contact> getContacts() {
    List<Contact> result = new ArrayList<Contact>();
    if (this.facebook != null) {
        result.add(new Contact("facebook", this.getId(), this.facebook));
    }
    if (this.twitter != null) {
        result.add(new Contact("twitter", this.getId(), this.twitter));
    }
    // ...
    return result;
}

在联系中设置一个身份证确实有意义,因为联系不是实体。

请注意,你的问题很奇怪:通常,你根据基本数据库图谋设计你的解放实体。 如你所述,如果基本图象是这样的话,为什么要照此设计。 这没有什么意义。





相关问题
Matrix to Represent a Triangle in Screen Space

So i have a set of four points in 3D Space. P1 [0, 0, 0] P2 [128, 0, 0] P3 [0, 128, 0] P4 [128, 128, 0] Which I m then projecting orthographically to the screen effectively giving me two ...

Using LINQ To SQL with multiple database tables

I have an employee class with as follows: public class Employee { public string FirstName { get; set; } public string LastName { get; set; } public string UserName { get; set; } ...

Mapping points from Euclician 2-space onto a Poincare disc

For some reason it seems that everyone writing webpages about Poincare discs is only concerned with how to represent lines and measure distances. I d like to morph a collection of 2D points (as ...

Fluent NHibernate, varbinary(max) and SQLite

I have a varbinary field in my sql server database that needs to be varbinary(max). I create my database with NHibernate and I use Fluent Nhibernate for my mappings. I also use SQLite for my unit ...

Javascript redirect

I am working with javascript and here is what I am trying to do: 1. Send a get request which looks like "http://localhost:8080/myapp/verify.htm?verifyId=Agkvhs" My requests reaches my verify.jsp in ...

热门标签