JSP NetBeans i Hibernate maly problem

0

Witam

Próbuję połączyć dwie technologie. Hibernate oraz JSP.

Jednak pojawia mi się błąd:

exception
org.apache.jasper.JasperException: org.hibernate.HibernateException: No CurrentSessionContext configured!
root cause
org.hibernate.HibernateException: No CurrentSessionContext configured!

Mam klasę Blog, która będzie mi obsługiwać hmm Encję Blog (class EBlog).

oto pliki:

hibernate.cfg.xml

<?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="current_session_context_class">thread</property>
    <property name="hibernate.connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>
    <property name="hibernate.connection.url">jdbc:derby://localhost:1527/test</property>
    <property name="hibernate.connection.username">test</property>
    <property name="hibernate.connection.password">test</property>

    
    <mapping class="Encje.EBlog" file="" jar="" package="Encje" resource="EBlog.hbm.xml"/>
  </session-factory>
</hibernate-configuration>

hibernate.properties

hibernate.connection.driver_class = org.apache.derby.jdbc.ClientDriver
hibernate.connection.url = jdbc:derby://localhost:1527/test
hibernate.connection.username = test
hibernate.connection.password = test
hibernate.c3p0.min_size = 5
hibernate.c3p0.min_max = 5
hibernate.c3p0.timeout = 300
hibernate.c3p0.max_statements = 50
hibernate.c3p0.idle_test_period = 3000

a Tutaj kod klasy:

public class Blog implements Serializable
{
    public Blog() throws IOException
    {
        
        Properties prop = new Properties();
        InputStream i = Blog.class.getResourceAsStream("hibernate.properties");
        prop.load(i);
    
        SessionFactory sf = new Configuration().addProperties(prop).configure("hibernate.cfg.xml").buildSessionFactory();
        sf.openSession();
        org.hibernate.Session session = sf.getCurrentSession();
        session.beginTransaction();
        Transaction trs = session.beginTransaction();    

        trs.commit();
        sf.close(); 
    }
}

Podobny problem miałem w aplikacji, którą pisałem testując hibernate nie używając jsp (dopiero zaczynam z jsp).
Problem się rozwiązał dodając: <property name="current_session_context_class">thread</property> w hibernate.cfg.xml

A teraz to nie wiem już co może być nie tak. Dodam że pliki konfiguracyjne się ładują.

Dzięki wielkie :)

Pozdrawiam

0

Dodam że wyjątek wyskakuje przy: org.hibernate.Session session = sf.getCurrentSession();

0

SessionFactory sf = new Configuration().addProperties(prop).configure("hibernate.cfg.xml").buildSessionFactory();

    <b>org.hibernate.Session session = sf.openSession();</b>
    session.beginTransaction();
    Transaction trs = session.beginTransaction();

Tak powinno być i działa :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1