我取得了一些成功。
类节点可以有多个单元,类单元可以有多个模块。所以,我用这种方式映射我的类:
Node:
@Entity
@Table(name="node")
@SecondaryTable(name="unit")
public class Node {
@Id
@Column(name = "nid")
private int nid;
@Column(name = "nnm")
private String nnm;
@Column(name = "nhwtype")
private int nhwtype;
@Column(name = "nstate")
private String nstate;
@Column(name = "ipaddress")
private String ipaddress;
@Column(name = "ipaddressrouterid")
private String ipaddressrouterid;
@Column(name = "eswversion")
private String eswversion;
@OneToMany
@JoinColumn(name="nid")
private Set<Unit> units;
Unit:
@Entity
@Table(name="unit")
public class Unit {
@Id
@Column(name="unnr")
private int unnr;
@Column(name="unhwtype")
private int unhwtype;
@Column(name="unslot")
private int unslot;
@OneToMany
@JoinColumn(name="unnr")
private Set<Module> modules;
Module:
@Entity
@Table(name="module")
public class Module {
@Id
@Column(name="mpos")
private int mpos;
@Column(name="mhwtype")
private int mhwtype;
现在hibernate正在创建这样的列表:
列表:
[0] nid 1
List<Unit> units
[0] List<Module> modules
[1] nid 1
List<Unit> units
[0] List<Module> modules
[2] nid 1
List<Unit> units
[0] List<Module> modules
我在节点列表中放置了一个单元列表,并将模块列表放在单元列表中。但是,我正在创建三个相同的索引,我不需要。因为只有一个人拥有我需要的所有信息。另一个问题是某些模块信息不一致。
原因可能是hibernate没有找到where子句正确。这就是为什么它留下了“?”
Hibernate日志:
Hibernate:
select
node0_.nid as nid1_2_,
node0_.eswversion as eswversi2_2_,
node0_.ipaddress as ipaddres3_2_,
node0_.ipaddressrouterid as ipaddres4_2_,
node0_.nhwtype as nhwtype5_2_,
node0_.nnm as nnm6_2_,
node0_.nstate as nstate7_2_
from
node node0_
left outer join
unit node0_1_
on node0_.nid=node0_1_.nid //Here it knows
where
node0_.nhwtype in (
10020 , 10021 , 10022 , 10023 , 10002 , 10017 , 10001
)
Hibernate:
select
units0_.nid as nid4_2_0_,
units0_.unnr as unnr1_3_0_,
units0_.unnr as unnr1_3_1_,
units0_.unhwtype as unhwtype2_3_1_,
units0_.unslot as unslot3_3_1_
from
unit units0_
where
units0_.nid=? //Here it dont know
Hibernate:
select
modules0_.unnr as unnr3_3_0_,
modules0_.mpos as mpos1_1_0_,
modules0_.mpos as mpos1_1_1_,
modules0_.mhwtype as mhwtype2_1_1_
from
module modules0_
where
modules0_.unnr=? //Here it dont know
表节点有一个PK nid。
表单位有一个PK unnr和一个FK nid。
表模块具有PK mpos和FK nid,FK unnr。