Problem mit Hibernate und IceFaces

Status
Nicht offen für weitere Antworten.

cuchulainn

Mitglied
Hi,

ich möchte IceFaces und Hibernate verwenden, aber es funktioniert nicht.

Hier sind meine Dateien:

HibernateUtil

Code:
package de.waldhausweg7.utils;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {
	private static HibernateUtil _instance = new HibernateUtil();
	private SessionFactory _sessionFactory;
	
    public static SessionFactory getSessionFactory() {
        return _instance._sessionFactory;
    }

	public static void closeSession(Session session) {
		try {
			if ((session != null) && (session.isOpen())) {
				session.close();
			}
		}
		catch (HibernateException he) {
		}
	}

	public static Session openSession() throws HibernateException {
		return openSession(getSessionFactory());
	}

	public static Session openSession(SessionFactory sessionFactory)
		throws HibernateException {

		return _instance._sessionFactory.getCurrentSession();
	}

	private HibernateUtil() {
        try {
			Configuration configuration = new Configuration();

			configuration = configuration.configure();

			_sessionFactory = configuration.buildSessionFactory();
        }
		catch (Exception e) {
        }
	}
}

personList.jspx
Code:
<f:view xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:ice="http://www.icesoft.com/icefaces/component">

<ice:outputDeclaration doctypeRoot="HTML"
                       doctypePublic="-//W3C//DTD XHTML 1.0 Transitional//EN"
                       doctypeSystem="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
    <title>Mieterliste</title>
</head>
<body>

	<ice:form>
		<ice:dataTable id="cultures" value="#{personService.personList}" var="row" border="1">

	    <h:column>
	    	<f:facet name="header">
	        	<ice:outputText value="Id"/>
	        </f:facet>
	        <h:outputText id="personId" value="#{row.personId}" />
	      </h:column>

	      <h:column>
	      	<f:facet name="header">
	        	<h:outputText value="Personenname"/>
	        </f:facet>
	        <h:outputText value="#{row.personName}"/>
	      </h:column>

		
		 <h:column>
	      	<f:facet name="header">
	        	<h:outputText value="Aendern"/>
	        </f:facet>

			<h:commandLink id="Edit" action="editPerson" actionListener="#{person.selectPerson}">
 				<h:outputText value="Aendern" />
 				<f:param id="selectId" name="selectId" value="#{row.personId}" />
 			</h:commandLink>
	      </h:column>

		 <h:column>
	      	<f:facet name="header">
	        	<h:outputText value="Loeschen"/>
	        </f:facet>

			<h:commandLink id="Delete" action="personList" actionListener="#{person.deletePerson}">
 				<h:outputText value="Löschen" />
 				<f:param id="deleteId" name="deleteId" value="#{row.personId}" />
 			</h:commandLink>
	      </h:column>
	    </ice:dataTable>
		

		<ice:commandButton action="addPerson" value="Person hinzufuegen" />
	</ice:form>
</body>
</html>
</f:view>

PersonService.java

Code:
package de.waldhausweg7.service;


import java.util.List;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import de.waldhausweg7.utils.HibernateUtil;
import de.waldhausweg7.model.Person;


public class PersonService {
	private List personList;


	public static void addPerson(Person person) throws Exception {
		Session session = null;

		try {
			session = HibernateUtil.getSessionFactory().getCurrentSession();
			session.beginTransaction();
			session.save(person);
			session.flush();
			session.getTransaction().commit();
		}
		catch(Exception e) {
			throw new Exception(e);
		}
		finally {
			HibernateUtil.closeSession(session);
		}
	}


	public static void deletePerson(int personId) throws Exception {
		Session session = null;


		try {
			session = HibernateUtil.openSession();
			session.beginTransaction();
			Person person = (Person)session.get(Person.class, personId);
			if (person != null) {
				session.delete(person);
				session.flush();
			}
			session.getTransaction().commit();
		}
		catch(Exception e) {
			throw new Exception(e);
		}
		finally {
			HibernateUtil.closeSession(session);
		}
	}


	public static void updatePerson(Person person) throws Exception {
		Session session = null;


		try {
			session = HibernateUtil.openSession();
			session.beginTransaction();
			session.update(person);
			session.flush();
			session.getTransaction().commit();
		}
		catch(Exception e) {
			throw new Exception(e);
		}
		finally {
			HibernateUtil.closeSession(session);
		}
	}


	public List getPersonList() throws Exception {
		Session session = null;


		try {
			System.out.println("Hallo 1.5!!!");
			session = HibernateUtil.openSession();
			System.out.println("Hallo 4!!!");
			session.beginTransaction();
			System.out.println("Hallo 2!!!");
			SQLQuery q = session.createSQLQuery("SELECT * FROM Person");
			System.out.println("Hallo 3!!!");
			q.addEntity(Person.class);
			personList = q.list();
			session.getTransaction().commit();
			return personList;
		}
		catch(Exception e) {
			throw new Exception(e);
		}
		finally {
			HibernateUtil.closeSession(session);
		}
	}


	public static Person getPerson(int personId) throws Exception {
		Session session = null;


		try {
			session = HibernateUtil.openSession();
			session.beginTransaction();
			Person person = (Person)session.get(Person.class, new Integer(personId));
			session.getTransaction().commit();
			return person;
		}
		catch(Exception e) {
			throw new Exception(e);
		}
		finally {
			HibernateUtil.closeSession(session);
		}
	}
}

Wenn meine personList.jspx die Methode PersonService.getPersonList() aufrufen möchte, bekommen ich diesen Fehler: javax.el.ELException: Error reading 'personList' on type de.waldhausweg7.service.PersonService

Weiß jemand, was falsch sein könnte?
 
Jetzt bekomme ich die Fehlermeldung: "Could not initialize class de.waldhausweg7.utils.HibernateUtil"

Dabei ist die kompilierte class-Datei vorhanden.
 
Ich selbst habe noch wenig Erfahrungen.
Folgendes habe ich schon gemerkt:
1. Wo ist deine Methode setPersonList(...)?
2. Hast Du Dein PersonService in der ApplicationContext.xml registriert?
 
Status
Nicht offen für weitere Antworten.

Zurück
Oben