我正在尝试为本地解决方案创建一个仪表板,该解决方案收集应用程序服务器的本机性能相关统计信息。这是各种代理收集的数据的 DDL。为简洁起见,我跳过了几列和不相关的表格。
create table server (
id integer not null auto_increment,
name varchar(50) not null,
primary key(id)
);
create table metric (
id integer not null auto_increment,
name varchar(50) not null,
primary key (id)
);
create table server_metric (
id integer not null auto_increment,
server_id integer not null,
metric_id integer not null,
constraint foreign key (server_fk) references server(id),
constraint foreign key (metric_fk) references metric(id),
primary key (id)
);
create table value (
id integer not null auto_increment,
server_metric_id integer not null,
value varchar(500) not null,
collect_time timestamp not null,
constraint foreign key (server_metric_fk) references server_metric(id)
primary key (id)
);
作为标准的一部分,仪表板应允许用户根据这些表中的任何列查看报告。所以我会根据用户的选择生成 Hibernate Criteria 查询。
当我对 POJO 进行逆向工程时,Metric 对象看起来像这样:
private long id;
private String name;
private Set serverMetrics = new HashSet(0);
... constructors, getters, setters truncated ...
我想做的是将 Metric 公开为上面这些表关系的单个 POJO。所以本质上你可以通过 Metric POJO 获取服务器的名称、值、时间戳。这将简单地生成 Criteria 查询,结果集将始终是 Metric 对象的列表。
我提到了这个链接——它适用于对象之间的一对一关系。但在我的情况下,metric 与 server_metric 有一对多的关系,依此类推......我不确定我的 Metric 表的映射文件如何实现相同的
任何帮助将不胜感激......
干杯!