@ManagedBean无法获取关系数据



我遇到了这个奇怪的问题,抛出了不太有用的错误。我试图在Primefaces表中显示实体Bean的数据。我有两个项目,一个用于前端,另一个用于后端。事情是,实体Bean有@OneToMany@ManyToOne关系,它们似乎导致了问题,因为如果我null它们没有错误发生,但我需要这些数据,所以它不是一个解决方案。

后端:

实体关键部分:

    @Entity
    @Table(name = "business_process_tasks")
    public class BusinessProcessTasks implements java.io.Serializable {
    ....
        @ManyToOne(fetch=FetchType.EAGER)
        @JoinColumn(name="process")
        public Process getProcess() {
        return process;
        }
        public void setProcess(Process process) {
            this.process = process;
        }
        @OneToMany(mappedBy = "processTask")
        public List<BusinessProcessTasksMeta> getMeta() {
            return meta;
        }
        public void setMeta(List<BusinessProcessTasksMeta> meta) {
            this.meta = meta;
        }
    }

EJB的关键部分:

@Override
public List<BusinessProcessTasks> getList(int processId) {
    EntityManager em = emf.createEntityManager();
    String q = "SELECT t from " + BusinessProcessTasks.class.getName() + " t where process="+processId;
    Query query = em.createQuery(q);
    List<BusinessProcessTasks> items = query.getResultList();
    for(int i = 0;i<items.size();i++){
        BusinessProcessTasks t = (BusinessProcessTasks) items.get(i);
                    //IF I SET THESE TO NULL NO ERRORS SHOW
        t.setProcess(null);
        t.setMeta(null);
    }
    em.close();
    return items;
}

前端:

@ManagedBean关键部件:

@ManagedBean(name = "processTasksTableBean")
@ViewScoped
public class ProcessTasksTableBean {
    .....
    @PostConstruct
    void initialiseSession() {
        System.out.println("Bean running");
        FacesContext.getCurrentInstance().getExternalContext().getSession(true);
            //GETTING ID FROM URL
        HttpServletRequest request = (HttpServletRequest) FacesContext
                .getCurrentInstance().getExternalContext().getRequest();
        pageProcessId = Integer.parseInt(request.getParameter("id"));
        processTasksBeanRemote = doLookup();
        //ONLY PLACE IN PROJECT WHERE ERROR IS REFERENCED IN CONSOLE IS HERE
        processTasksList = processTasksBeanRemote.getList(pageProcessId);
    }
.....
}

Eclipse console - log很长,如果需要,我会把它全部贴出来,现在只是关键部分:

09:34:58,377 SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (http-localhost-127.0.0.1-8189-3) Error Rendering View[/ProcessTasks.xhtml]: java.lang.IllegalStateException: JBAS011048: Failed to construct component instance
Caused by: java.lang.RuntimeException: ClassNotFoundException marshaling EJB parameters
Caused by: java.lang.ClassNotFoundException: org.hibernate.collection.internal.PersistentBag from [Module "deployment.bpmweb.war:main" from Service Module Loader]
09:34:58,403 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/bpmweb].[Faces Servlet]] (http-localhost-127.0.0.1-8189-3) Servlet.service() for servlet Faces Servlet threw exception: java.lang.ClassNotFoundException: org.hibernate.collection.internal.PersistentBag from [Module "deployment.bpmweb.war:main" from Service Module Loader]

问题解决了,我从http://mvnrepository.com/artifact/org.hibernate/hibernate-core/4.3.4.Final下载了最新的Hibernate核心,一切似乎都很好。非常奇怪,因为我通过构建路径将Jboss运行时库添加到每个项目中。

相关内容

  • 没有找到相关文章

最新更新