Al Salam Alaykom,
我正在尝试在设备和位置类之间的一对多关系中使用hibernate注释,一个设备有许多位置。我在选择设备时得到一个空位列表的问题,我尝试了很多解决方案而没有解决问题
这是我班级中的关系部分:
Device.java
@GwtTransient
private List<Position> positions = new LinkedList<Position>();
@OneToMany(mappedBy="device")
public List<Position> getPositions() {
return positions;
}
public void setPositions(List<Position> positions) {
this.positions = positions;
}
@GwtTransient
private List<Position> positions = new LinkedList<Position>();
@OneToMany(mappedBy="device")
public List<Position> getPositions() {
return positions;
}
public void setPositions(List<Position> positions) {
this.positions = positions;
}
和Position.java
private Device device;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "device_id")
public Device getDevice() {
return device;
}
public void setDevice(Device device) {
this.device = device;
}
另外,我尝试了以下注释:
private Device device;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "device_id")
public Device getDevice() {
return device;
}
public void setDevice(Device device) {
this.device = device;
}
/ ******************* ************** /
//In Device:
@OneToMany(mappedBy = "device")
@LazyCollection(LazyCollectionOption.FALSE)
//In Position:
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({@JoinColumn(name = "device_id", insertable=false, updatable=false)})
//In Device:
@OneToMany(mappedBy = "device")
@LazyCollection(LazyCollectionOption.FALSE)
//In Position:
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({@JoinColumn(name = "device_id", insertable=false, updatable=false)})
/ ******************* ************** /
//In Device:
@OneToMany(mappedBy = "device",fetch = FetchType.EAGER)
@LazyCollection(LazyCollectionOption.FALSE)
@Fetch(FetchMode.SELECT)
//In Position:
@ManyToOne
@JoinColumn (name="device_id")
//In Device:
@OneToMany(mappedBy = "device",fetch = FetchType.EAGER)
@LazyCollection(LazyCollectionOption.FALSE)
@Fetch(FetchMode.SELECT)
//In Position:
@ManyToOne
@JoinColumn (name="device_id")
/ ******************* ************** /
//In Device:
@OneToMany(mappedBy = "device")
@LazyCollection(LazyCollectionOption.FALSE)
//In Position:
@ManyToOne
@PrimaryKeyJoinColumn
任何帮助将不胜感激......谢谢