【问题标题】:hibernate with web service使用 Web 服务休眠
【发布时间】:2011-09-25 06:31:14
【问题描述】:

在阅读我的问题之前,这项工作在一个普通的动态 Web 项目中 我创建了一个像这样的方法的 Web 服务: http://www.youtube.com/watch?v=o2Vjs8ylmFM 使用 CFX 2.4 和 2.5 动态 Web 模型版本,当我在由 Web 服务生成的当前客户端 Web 项目中运行休眠时,我得到一个异常 就是这样:

  Etat HTTP 500 - 

     --------------------------------------------------------------------------------

      type Rapport d''exception

      message 

      description Le serveur a rencontré une erreur interne () qui l'a empêché de satisfaire la                 requête.

       exception 

       org.apache.jasper.JasperException: Impossible de compiler la classe pour la JSP: 

        An error occurred at line: 1 in the generated java file
        The type net.sf.hibernate.Session cannot be resolved. It is indirectly referenced from         required .class files

         Une erreur s'est produite à la ligne: 16 dans le fichier jsp: /JSP/ebook/index.jsp
          Session cannot be resolved to a type
         13: <BODY> 
         14: <%
         15: 
         16: Session hibernateSession = HibernateUtil.currentSession();
         17: Transaction tx = hibernateSession.beginTransaction(); 
         18: 
         19: Etudinat etudiant = new Etudinat();


         Une erreur s'est produite à la ligne: 16 dans le fichier jsp: /JSP/ebook/index.jsp

而我的 hibernateUtil 类是:

package DBase;

import net.sf.hibernate.*;

import net.sf.hibernate.cfg.*;


 public class HibernateUtil {

 private static final SessionFactory sessionFactory;

 static {
 try {
 // Crée la SessionFactory
 sessionFactory =
 new Configuration().configure().buildSessionFactory();
 } catch (HibernateException ex) {
 throw new RuntimeException("Problème de configuration : "
 + ex.getMessage(), ex);
 }
 }

 public static final ThreadLocal session = new ThreadLocal();

  public static Session currentSession()
  throws HibernateException {
  Session s = (Session) session.get();
 // Ouvre une nouvelle Session, si ce Thread n'en a aucune
 if (s == null) {
 s = sessionFactory.openSession();
 session.set(s);
 }
 return s;
}

而我的 hibernate.cfg.xml 页面是:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
<session-factory >

<!-- local connection properties -->
<property name="hibernate.connection.url">jdbc:mysql://localhost/ebook</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">162826</property>
<!-- property name="hibernate.connection.pool_size"></property -->

<!-- dialect for MySQL -->
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>



 <!-- Echo all executed SQL to stdout -->
 <property name="show_sql">true</property>

  <property name="current_session_context_class">thread</property>

  <mapping resource="DBase/Favorieensei.hbm" />
  <mapping resource="DBase/Ajouter.hbm" />
  <mapping resource="DBase/Favorie.hbm" />
  <mapping resource="DBase/Enseignant.hbm" />

这是我的页面jsp

<%@page import="DBase.HibernateUtil"%>
<%@ page import="java.io.*" %> 
<%@ page import="java.util.*" %> 
<%@ page import="DBase.*" %> 
<%@ page import="net.sf.hibernate.*" %> 
<%@ page import="net.sf.hibernate.cfg.*" %> 

<HTML> 
<HEAD> 
<title>Greetings!</title> 
</HEAD>  
  <BODY> 
<%

 Session hibernateSession = HibernateUtil.currentSession();
  Transaction tx = hibernateSession.beginTransaction(); 

  Etudinat etudiant = new Etudinat();
  etudiant.setUserName("davido");
 etudiant.setPassword("mioo");
  etudiant.setQuestion("best music");
   etudiant.setAnswer("rock");
   etudiant.setEmail("david@live.fr");
  etudiant.setNom(".....");
  etudiant.setPrenom("....");
  etudiant.setSexe("Homme");

   etudiant.setIDFilliere(Filliere.INFORMATIQUE);
  hibernateSession.save(etudiant); 
  tx.commit();
  HibernateUtil.closeSession();


  %> 


  <br> 
 <br> 
 <br> 
 <br> 
  <table width="400" border="0" cellspacing="1" cellpadding="0" align="center" class="tableBox"> 
  <tr> 
  <td CLASS="bluebanner" align="center"> Greetings, </TD> 
    </tr> 
  </table> 
    </BODY> 
    </HTML>

这是我的截图

请帮助我们按时运行,我还剩 3 个时间完成它

【问题讨论】:

    标签: eclipse web-services hibernate jsp


    【解决方案1】:
     An error occurred at line: 1 in the generated java file
        The type net.sf.hibernate.Session cannot be
    

    已解决。它被间接引用 来自所需的 .class 文件

    显然你的类路径有问题。确认您正在按要求导入所有内容(乍一看这对我来说似乎是正确的),并且您的 hibernate.jar 位于正确的文件夹中并在执行期间正确获取 loadet。

    【讨论】:

    • 我们更改了休眠 jar,并使用 net.sf.hibernate.Session 下载了另一个 Hibernate2.0.3.jar,但是 sessionn 是这个 jar 中的一个接口而不是一个类,我们得到了同样的错误 plz你能帮我吗
    • 您是否验证了 jarfile 是否在当前文件夹中并正确加载?
    • 是的,jar 位于当前文件夹中,并且已正确加载,我打开 eclipse 并在那里找到了 session.class,但我遇到了同样的错误
    • 'Found by eclipse' 与'found by tomcat' 不同,后者显然是在托管应用程序。通常,您会将库放在 WEB-INF/lib 文件夹中(并确保它们与您的应用程序一起部署)。我猜谷歌上有很多“无法引用 tomcat 类”的点击率。
    • 所以我将 jars 放在 WEB-INF/lib 文件夹中,并在 java 构建路径中引用这些 jars?你是什​​么意思(我想在谷歌上有很多“无法引用 tomcat 类”的点击率。)
    猜你喜欢
    • 2018-02-04
    • 1970-01-01
    • 1970-01-01
    • 2018-11-20
    • 2015-10-14
    • 1970-01-01
    • 1970-01-01
    • 2016-01-18
    • 2012-04-25
    相关资源
    最近更新 更多