2014-01-11 50 views
0

我想从我的数据库中检索数据并将其导入到数据表中的JSF视图中,但存在我无法解决的Exception问题。我复制了必要的jar文件到lib文件夹,这里是名单:JSF视图无法从数据库中恢复数据

  • JSF-api.jar中
  • JSF-impl.jar中
  • JSTL-API-1.2.jar
  • JSTL,IMPL -1.2.jar

这里是JSF视图的代码:listFournisseur.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:f="http://java.sun.com/jsf/core"> 

<head> 
<link rel="stylesheet" type="text/css" href="../css/styles.css"/> 
</head> 

<h:body> 
<h:form> 
<h:dataTable var="fournisseur" value="#{fournisseurBean.listFournisseurs}" border="1"> 
<h:column> 
<f:facet name="header"> 
<h:outputLabel value="nom" /> 
</f:facet> 
#{fournisseur.nomfour} 
</h:column> 
<h:column> 
<f:facet name="header"> 
<h:outputLabel value="raison sociale" /> 
</f:facet> 
#{fournisseur.raisonsfour} 
</h:column> 
<h:column> 
<f:facet name="header"> 
<h:outputLabel value="Adresse" /> 
</f:facet> 
#{fournisseur.adressef} 
</h:column> 
</h:dataTable> 
</h:form> 
</h:body> 
</html> 

这里是ManagedBean的代码:FournisseurBean.java

package com.fst.bibliotheque.beans; 

import java.util.List; 

import com.fst.bibliotheque.dao.FournisseurHome; 
import com.fst.bibliotheque.persistance.Fournisseur; 
import com.fst.bibliotheque.services.FournisseurService; 

public class FournisseurBean { 

private FournisseurService gestionFournisseur; 
private List<Fournisseur> listFournisseurs; 
    private int tailleListe; 

public List<Fournisseur> getListFournisseurs() { 

    if(gestionFournisseur==null) 
     gestionFournisseur=new FournisseurService(); 
    listFournisseurs=gestionFournisseur.findAllList(); 
    tailleListe=listFournisseurs.size(); 
    return listFournisseurs; 

} 

public void setListFournisseurs(List<Fournisseur> listFournisseurs) { 
    this.listFournisseurs = listFournisseurs; 
} 


    } 

最后这里是关联到层的服务的代码:其中位于梅索德RESPONSABLE用于检索数据FournisseurServices.java。

package com.fst.bibliotheque.services; 

import java.util.List; 
import org.hibernate.Session; 
import org.hibernate.Transaction; 
import com.fst.bibliotheque.dao.FournisseurHome; 
import com.fst.bibliotheque.dao.HibernateUtil; 

public class FournisseurService { 

private FournisseurHome dao; 

public FournisseurService() { dao = new FournisseurHome() ; } 

public List findAllList() { 

    Session session=HibernateUtil.getSessionFactory().getCurrentSession(); 
    Transaction tx= null ; 
    List l=null; 
    try{ 
     tx=session.beginTransaction(); 
     l=dao.findAll(); 
     tx.commit() ; 
     }catch(RuntimeException ex){ 
      if(tx!= null) tx.rollback(); 
      ex.printStackTrace() ; } 
return l; 
} 

} 

功能findAllList()调用位于DAO的层的findAll()函数: Fournisseurdao.java:

package com.fst.bibliotheque.dao; 

// Generated Dec 7, 2013 2:15:19 AM by Hibernate Tools 3.4.0.CR1 

import java.util.List; 
import javax.naming.InitialContext; 
import org.apache.commons.logging.Log; 
import org.apache.commons.logging.LogFactory; 
import org.hibernate.Criteria; 
import org.hibernate.LockMode; 
import org.hibernate.SessionFactory; 
import org.hibernate.criterion.Order; 

import com.fst.bibliotheque.persistance.Fournisseur; 

import static org.hibernate.criterion.Example.create; 

/** 
* Home object for domain model class Fournisseur. 
* @see com.fst.bibliotheque.dao.Fournisseur 
* @author Hibernate Tools 
*/ 
public class FournisseurHome { 

private static final Log log = LogFactory.getLog(FournisseurHome.class); 

private final SessionFactory sessionFactory = getSessionFactory(); 

protected SessionFactory getSessionFactory() { 
    try { 
     return HibernateUtil.getSessionFactory(); 
    } catch (Exception e) { 
     log.error("Could not locate SessionFactory in JNDI", e); 
     throw new IllegalStateException(
       "Could not locate SessionFactory in JNDI"); 
    } 
} 

public List findAll() { 
    Criteria crit  =sessionFactory.getCurrentSession().createCriteria(Fournisseur.class); 
    return crit.list(); 
} 
public List findAll (Order defaultOrder) { 
    Criteria crit = sessionFactory.getCurrentSession().createCriteria(Fournisseur.class); 
    if (null != defaultOrder) crit.addOrder(defaultOrder); 
    return crit.list(); 
} 
} 

执行后,我得到这个异常:

SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/BibliothequeJSFHib1] threw exception [org/hibernate/Session] with root cause 
java.lang.ClassNotFoundException: org.hibernate.Session 

没有任何人有任何想法如何解决它?

回答

0

Your FournisseurService - Class试图打开一个Hibernate-Session。

public class FournisseurService { 
    public List findAllList() { 
     Session session=HibernateUtil.getSessionFactory().getCurrentSession(); 
     ... 
    } 
} 

Hibernate的Session,一个ORM映射器(数据库-东西),是Hibernate-Core库的一部分,已被添加到您的项目。

+0

事实上,我创建了一个库,其中我添加了hibernate jar's..i删除这个库,并将jar复制到文件夹lib中,问题解决了:) thx很多。 – user3179505