简体   繁体   English

远程访问Jpa实体

[英]Remote Access To Jpa Entity

I'm currently working on system that consists of Java Web app and C# client app. 我目前正在使用由Java Web应用程序和C#客户端应用程序组成的系统。 Web app has Java Web Service, which has method that returns entity object of Program class: Web应用程序具有Java Web Service,该Java Web Service具有返回Program类的实体对象的方法:

@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: 此类型为Program的返回对象,具有许多属性和关系:

@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.name,它是从DbEntity继承的,但是当我尝试调用类似的内容时:

program.logo.name

client throws NullReferenceException. 客户端抛出NullReferenceException。 Same exception occurs when i try to iterate over the elements of programPlaylistList ArrayList. 当我尝试遍历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. 编辑好,所以我打印出客户端从服务获得的XML响应,并正确填充了该响应,但是由于某些原因,没有填充对象字段,并且大多数情况下为null。 Why is this occurring? 为什么会这样呢?

默认情况下,@OneToMany批注的获取策略为LAZY ,是否尝试过像@oneToOne字段中那样将其指定给EAGER(fetch = FetchType.EAGER)?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Hibernate(JPA)中的并发实体访问 - Concurrent entity access in Hibernate (JPA) EJB 3.1 远程访问 + Jboss 7.3 +JPA - EJB 3.1 remote access + Jboss 7.3 +JPA Spring with JPA:将来自不同请求的对JPA实体的并发访问排队 - Spring with JPA: Queue concurrent access to JPA entity from different requests Spring Boot-在控制器方法中访问JPA实体属性 - Spring Boot - Access JPA entity properties in controller method 问题! 是否使用数据访问对象(dao)和JPA提取实体数据? - Problems! Entity data are not fetched using data access object (dao) and JPA? 在JPA中,实体是否可以访问其嵌入对象的嵌入式? - In JPA does an entity have access to the Embedded of its Embedded object? 如何使用带有Spring Boot的Lombok访问JPA实体的Builder()? - How to access Builder() of a JPA entity using Lombok with Spring Boot? 在JPA中,我可以访问由@OrderColumn创建的字段到收集的实体中吗? - In JPA can I access the field created by the @OrderColumn into the collected entity? JPA中@Access annoation的用途是什么意思在实体级别? - What is the use of the @Access annoation in JPA means at the Entity level? 带 JPA 的 Hibernate 5:在实体中没有指定架构的休眠访问 - Hibernate 5 with JPA : hibernate access without schema spécified in entity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM