I'm currently working on system that consists of Java Web app and C# client app. Web app has Java Web Service, which has method that returns entity object of Program class:
@WebMethod(operationName = "getProgram")
public Program getProgram(@WebParam(name = "macAddress") String macAddress){
Device device = DeviceManager.getInstance().getDevice(macAddress);
if(device != null){
return device.getProgram();
}
return null;
}
This return object of type Program which has many properties and relations:
@Entity
@Table(name = "PROGRAM", schema = "APP")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Program.getProgramsByWeather", query = "SELECT p FROM Program p WHERE p.weather = :weather")})
public class Program extends DbEntity implements Serializable {
private static final long serialVersionUID = 1L;
@JoinColumn(name = "LOGO_ID", referencedColumnName = "ID")
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch= FetchType.EAGER)
private Logo logo;
@JoinColumn(name = "WEATHER_ID", referencedColumnName = "ID")
@ManyToOne
private Weather weather;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "program", orphanRemoval = true)
private List<ProgramPlaylist> programPlaylistList = new ArrayList<>();
@OneToMany(cascade = CascadeType.ALL, mappedBy = "program", orphanRemoval = true)
private List<ProgramTicker> programTickerList = new ArrayList<>();
@Column(name = "UPDATED")
private boolean updated;
public Program() {
}
public Program(String name, AppUser owner) {
super(name, owner);
}
public Logo getLogo() {
return logo;
}
public void setLogo(Logo logo) {
this.logo = logo;
}
public Weather getWeather() {
return weather;
}
public void setWeather(Weather weather) {
this.weather = weather;
}
public boolean isUpdated() {
return updated;
}
public void setUpdated(boolean updated) {
this.updated = updated;
}
@XmlElement
public List<ProgramPlaylist> getProgramPlaylistList() {
return programPlaylistList;
}
@XmlElement
public List<ProgramTicker> getProgramTickerList() {
return programTickerList;
}
@Override
public String toString() {
return "Program[ id=" + getId() + " ]";
}
}
Client can get this object and accessing some properties in client app like program.name, which it inherits from DbEntity , but when i try to call something like this:
program.logo.name
client throws NullReferenceException. Same exception occurs when i try to iterate over the elements of programPlaylistList ArrayList.
I'm assuming that the object itself that is passed through to client isn't fully loaded.
How can i solve this problem, please help?!
EDIT Ok, so I printed out XML response that client get from service and its populated correctly, but for some reason object fields aren't populated and are mostly null. Why is this occurring?
默认情况下,@OneToMany批注的获取策略为LAZY ,是否尝试过像@oneToOne字段中那样将其指定给EAGER(fetch = FetchType.EAGER)?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.