0

问题陈述

假设您有带有属性调用状态的报告,但需要记录每个状态更改以及由哪个用户记录。所以你很可能最终会得到

REPORT
REPORT_ID

REPORT_STATUS
STATUS_ID
REPORT_ID

但是我应该如何在没有“计算”的情况下获得当前状态(即获取最后修改日期)

我想出了这个解决方案

REPORT
REPORT_ID
CURRENT_STATUS_ID

REPORT_STATUS
STATUS_ID
REPORT_ID

假设您需要更多属性,我怀疑这种创建表的方式在尝试CREATE REPORT然后尝试时与休眠有一些问题CREATE STATUS

我只是尝试使用注释为这种关系创建休眠映射。我试图拯救的每个人..我明白了

未找到 STATUS_REPORT_PK 父键

这意味着当试图创建报表状态时,报表还没有创建。

如何进行正确的映射以允许我同时提交两者

4

1 回答 1

0

There seems to be a logical inconsistency here

Lets say we need to generate a report. Now the report_id is stored but we need a status ID.

But to get a new status we need to specify a report. Since the report is not created the status can't be created and vice versa.

I'm assuming there are a limited number of status's so lets store them in a table called STATUS

REPORT
REPORT_ID
CURRENT_STATUS_ID

REPORT_STATUS
STATUS_ID
REPORT_ID

STATUS
STATUS_ID

First create a new report and attach an object of status to it. Then create an object of REPORT_STATUS

Just in case you've set a cascade type remove it. Hibernate gets confused sometimes.

EDIT

You seem to be confused over the tables

The report table will hold the report id, data about the report as well as its current status

The report_status table will hold all the previous status's of the report as well as the current one represented as a composite primary key of status_id and report_id

The status table will hold ALL the possible status's a report can have. For eg. If the possible status's are "On Hold","In production", "Released", "editing" , these will be stored in the status table.

The other 2 tables will reference this for the status they are referring to.

于 2013-08-15T09:20:45.373 回答