@ManagedBean发布获取关系数据的问题

时间:2014-03-20 07:38:26

标签: primefaces ejb entity persistence database-relations

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

BACKEND:

实体的关键部分:

    @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;
}

FRONTEND:

@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控制台 - 日志很长,如果需要,我会发布所有内容,现在只是关键部分:

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]

1 个答案:

答案 0 :(得分:0)

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