-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Probleme mit Tomcat und Hibernate
PostPosted: Tue Jun 06, 2006 6:15 am 
Newbie

Joined: Tue Jun 06, 2006 5:54 am
Posts: 4
Hallo,

ich habe folgendes Problem. Wenn ich meine Anwendung löschen will bleibt immer eine Jar Datei (ojdbc14.jar)auf dem Server liegen. Diese läst sich erst durch herunterfahren des Servers löschen. Daraus schließe ich das eine Datenbankverbindung nicht richtig abgebaut wurde. Ich poste hier mal meinen Code. Ich hoffe jemand kann mir helfen.

Tomcat: 5.5
Hibernat 3.1
Oracle: 10g


Servlet

Code:
package model;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import util.HibernateUtil;

public class MTSTableView extends HttpServlet {

   protected void doGet(HttpServletRequest request, HttpServletResponse response)
                                 throws ServletException, IOException {

         
      try {
           // Begin unit of work
           HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
           PrintWriter out = response.getWriter();
          out.println("<html><head><title>Übersicht </title></head><body>");
      
          listEvents(out);

          //Write HTML footer
          out.println("</body></html>");
          out.flush();
          out.close();
          
           // End unit of work
           HibernateUtil.getSessionFactory()
                   .getCurrentSession().getTransaction().commit();
           HibernateUtil.getSessionFactory().close();

       } catch (Exception ex) {
           HibernateUtil.getSessionFactory()
                   .getCurrentSession().getTransaction().rollback();
           throw new ServletException(ex);
       }
      
      }

   private void listEvents(PrintWriter out) {
      
      List result = HibernateUtil.getSessionFactory()
        .getCurrentSession().createCriteria(MtsTabelle.class).list();
   

       if (result.size() > 0) {
           out.println("<h2>Tabellen</h2>");
           out.println("<table border='1'>");
           out.println("<tr>");
           out.println("<th>Objekt ID</th>");
           out.println("<th>SchemaName</th>");
           out.println("</tr>");
           for (Iterator it = result.iterator(); it.hasNext();) {
               MtsTabelle mts = (MtsTabelle) it.next();
               out.println("<tr>");
               out.println("<td>" + mts.getId()+ "</td>");
               out.println("<td>" + mts.getSchemaName() + "</td>");
               out.println("<td>" + mts.getFachbereich()+ "</td>");
               out.println("</tr>");
           }
           out.println("</table>");
       }
    
   }
   
}



HibernateUtil
Code:
package util;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.*;
import org.hibernate.cfg.*;

public class HibernateUtil {
   
   private static final SessionFactory sessionFactory;

    static {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            sessionFactory = new Configuration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }


}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 08, 2006 3:43 pm 
Newbie

Joined: Thu Feb 16, 2006 2:05 pm
Posts: 10
Location: Nürnberg, Germany
Ich weiss nicht, ob es daran liegt, aber meiner Ansicht nach solltest Du die Zeile

HibernateUtil.getSessionFactory().close();

besser in einen finally-Block unterhalb von Deiner Exception stecken.
Dieser Befehl schliesst die Datenbank-Verbindung.
In Deiner Variante bleibt die Datenbank-Verbindung offen, falls eine Exception aufgetreten ist.

_________________
Please rate this post, if it helped you.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 13, 2006 2:16 am 
Newbie

Joined: Tue Jun 06, 2006 5:54 am
Posts: 4
Ja erstmal vielen Dank für deine Antwort ich habe meinen Code nun um deine Zeile erweitert.

Code:
package util;

import org.hibernate.*;
import org.hibernate.cfg.*;

public class HibernateUtil {
   
   private static final SessionFactory sessionFactory;

    static {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            sessionFactory = new Configuration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        } finally {
           HibernateUtil.getSessionFactory().close();

        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }


}



Leider hat es nicht den gewünschten Effekt gebracht. Das Problem beleibt bestehen. Könnte es vielleicht an der Konfigurationsdatei liegen also an der hibernate.cfg.xml Hier mal der Code

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

<hibernate-configuration>

    <session-factory>
       
        <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="connection.url">jdbc:oracle:thin:@TEST:1521:TESTI</property>
        <property name="connection.username">test</property>
        <property name="connection.password">test</property>
     
        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>
      
        <!-- Enable Hibernate's automatic session context management -->
         <property name="current_session_context_class">thread</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>
               
       
        <!-- Drop and re-create the database schema on startup -->
        <!-- <property name="hbm2ddl.auto">create</property>-->

        <mapping resource="model/TestTabelle.hbm.xml"/>
      
    </session-factory>

</hibernate-configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 13, 2006 2:52 am 
Newbie

Joined: Tue Jun 06, 2006 5:54 am
Posts: 4
Es scheint wohl doch kein Hibernate Problem zu sein denn auch wenn ich per JDBC den Zugriff realisiere, kann das ojdbc14.jar nicht gelöscht werden. Hat jemand vielleicht trotzdem eine Idee woran das liegen kann.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 13, 2006 4:04 am 
Newbie

Joined: Tue Jun 06, 2006 5:54 am
Posts: 4
So ich habe das Problem gelöst. es lag wohl an einer Falschen Version des Jar File. Es gibt den Jdbc Treiber für die Oracle DB in verschiedenen Version nun klappt alles.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.