English 中文(简体)
单向一对一地图绘制成多个领域
原标题:Bidirectional one-to-one mapped to multiple fields

我有一个称为<代码>Flight的域级,即飞行流动。 我有另一个称为<代码>Movement的班子,可以代表离境或抵达,并载有出行的日期和时间以及机场。

@Entity
public class Flight implements Serializable {

    private Movement departure;
    private Movement arrival;
}

@Entity
public class Movement implements Serializable {
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateTime;
    @ManyToOne
    private Airport airport;

    private Flight flight;
}

不过,我不清楚如何在<代码>Movement类别中适当标明<> > 飞行领域。 页: 1

@OneToOne
private Movement departure;
@OneToOne
private Movement arrival;

然而,这是一个问题。 页: 1 两个领域:

// This obviously does not work
@OneToOne(mappedBy = "departure")
@OneToOne(mappedBy = "arrival")
private Flight flight;

我将如何适当说明这一点,同时附上<条码>部分和<条码>。 外地适当参考<代码>Movement,并仍然能够在<代码><> /code> 领域<代码> 类别查询<代码>。

最佳回答

如果你真的需要双向关系,那么你就不得不进入行动区,其中之一永远无效:

@OneToOne(mappedBy = "departure")
private Flight departureFlight;

@OneToOne(mappedBy = "arrival")
private Flight arrivalFlight;

But you could have a single getter:

public Flight getFlight() {
    return departureFlight == null ? arrivalFlight : departureFlight;
}
问题回答

如果你需要两种方式的关系,你可以将关系类型改为@ 许多ToMany,因此,你可以使用附有附加地位栏的合并表格。 请具体说明它是否到达或离开。

Wikibooks提供了如何绘制地图的例子。 然而,这种关系在法典中很难处理。

或者,正如缓慢的学者所建议的那样,你可能根本不需要两种方式的关系? 绘制地图、使用和加快运行将更加简单。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签