# Seam Anwendung EAR-Projekt



## thommy.s (10. Dez 2010)

Hallo,

ich baue ein Tool zur Neuregistrierung von Accounts für Ressourcen eines Betriebs mit dem Seam Framework.

Mehr oder minder ist das das erste Mal, dass ich dieses in seiner ganzen Tief (mit EJB's Ver.3 und Hibernate) nutze.

Nun habe ich folgendes Problem:

Die Anfragenden für einen Account werden inner DB gespeichert, als Admin kann ich diese anzeigen lassen. Wenn Anfragen offensichtlich "müll" sind, sollen sie einfach gelöscht werden können. Dieses habe ich über eine anklickbare Datentabelle realisiert, siehe folgender JSF-Code:


```
<!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:a4j="http://richfaces.org/a4j"
      xmlns:rich="http://richfaces.org/rich"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"> 

<head>
<title>Übersicht Anfragende</title>
        <script type="text/javascript">
function confirmDelete()
{
    return confirm("Sind Sie sicher, dass Sie die Person löschen wollen? Diese Aktion kann nicht rückgängig gemacht werden");
}
        </script>
</head> 
<body>


<h:form>
	<h:dataTable var="records" value="#{persons}" border="1">
		<f:facet name="header">
			<h:outputText value="Anfragende für Accountregistrierung" />
		</f:facet>
		<h:column>
			<f:facet name="header">
				<h:outputText value="Titel" />
			</f:facet>
			<h:outputText value="#{records.title}"/>
		</h:column>
		<h:column>
			<f:facet name="header">
				<h:outputText value="Vorname" />
			</f:facet>
			<h:outputText value="#{records.givenname}"/>
		</h:column>
		<h:column>
			<f:facet name="header">
				<h:outputText value="Nachname" />
			</f:facet>
			<h:outputText value="#{records.surname}"/>
		</h:column>
		<h:column>
			<f:facet name="header">
				<h:outputText value="Abteilung/Struktureinheit" />
			</f:facet>
			<h:outputText value="#{records.depart}"/>
		</h:column>
		<h:column>
			<f:facet name="header">
				<h:outputText value="Mailadressse" />
			</f:facet>
			<h:outputText value="#{records.mail}"/>
		</h:column>
		<h:column>			
			<h:commandLink action="#{admin.delete()}" value="Löschen" onclick="return confirmDelete()"/>
		</h:column>
		<h:column>
			<h:commandLink value="Bearbeiten" action="#{admin.edit()}" />
		</h:column>
		<h:column>
			<f:facet name="header">
				<h:outputText value="PDF-Versand" />
			</f:facet>
			<h:commandLink value="PDF versenden" action="#{admin.sendPDF()}" />
		</h:column>
	</h:dataTable>
</h:form>
</body> 
</html>
```

Die dahinter liegende Methode hat folgenden Code:


```
package org.thommys.regusers.session;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.datamodel.DataModel;
import org.jboss.seam.annotations.datamodel.DataModelSelection;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.faces.Renderer;
import org.thommys.regusers.entity.DataTable;
import org.thommys.regusers.entity.Person;

/**
 * @author thommy
 *
 */
@Stateless
@Name("admin")
public class AdminBean implements Admin{
	
	@PersistenceContext
	private EntityManager em;
	
	@DataModelSelection
	private Person person;
	
	@DataModel
	private List<Person> persons;
	
	@In(value="data") @Out
	private DataTable data;
	
	@In(create=true)
	private Renderer renderer;
	
	@In
	private FacesMessages facesMessages;
	
	

	@SuppressWarnings("unchecked")	
	@Factory("persons") 
	public void getPersons() {
		
		//person = new Person();
		
		persons = em.createQuery("select p from Person p").getResultList();
						
		
	}
	
	public String delete() {
		
		System.out.println("Will jetzt was löschen...");
		
		Person toDelete = em.merge(person);
		em.remove(toDelete); //Sobald dieser Code ausgeführt wird, gibt es die gleich folgende Fehlermeldung
		getPersons();
		
		return null;
		
		
	}

}
```

Sobald ich die Methode ausführe, gibt es diese Fehlermeldung:


```
17:58:23,896 ERROR [TxPolicy] javax.ejb.EJBTransactionRolledbackException: EntityManagerFactory not found in JNDI : java:comp/env/RegisterUsers/pu
17:58:23,897 SEVERE [application] javax.ejb.EJBTransactionRolledbackException: EntityManagerFactory not found in JNDI : java:comp/env/RegisterUsers/pu
javax.faces.el.EvaluationException: javax.ejb.EJBTransactionRolledbackException: EntityManagerFactory not found in JNDI : java:comp/env/RegisterUsers/pu
	at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
	at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
	at javax.faces.component.UICommand.broadcast(UICommand.java:387)
	at javax.faces.component.UIData.broadcast(UIData.java:938)
	at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
	at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
	at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
	at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
	at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
	at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
	at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
	at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
	at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
	at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
	at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
	at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
	at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
	at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
	at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
	at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
	at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
	at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
	at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
	at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
	at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
	at java.lang.Thread.run(Thread.java:662)
Caused by: javax.ejb.EJBTransactionRolledbackException: EntityManagerFactory not found in JNDI : java:comp/env/RegisterUsers/pu
	at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:115)
	at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
	at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:194)
	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
	at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
	at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
	at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptorv2.invoke(RoleBasedAuthorizationInterceptorv2.java:201)
	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
	at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:186)
	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
	at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41)
	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
	at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67)
	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
	at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
	at org.jboss.ejb3.session.SessionSpecContainer.invoke(SessionSpecContainer.java:176)
	at org.jboss.ejb3.session.SessionSpecContainer.invoke(SessionSpecContainer.java:216)
	at 

usw.
```

Die EntityManagerFactory wird also in JNDI nicht gefunden. 

In der persistence.xml ist sie aber korrekt eingetragen

[XML]
<?xml version="1.0" encoding="UTF-8"?>
<!-- Persistence deployment descriptor for tests -->
<persistence xmlns="http://java.sun.com/xml/ns/persistence" 
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" 
             version="1.0">

   <persistence-unit name="RegisterUsers">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:/DefaultDS</jta-data-source>
      <properties>
         <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
         <property name="hibernate.show_sql" value="true"/>
         <property name="hibernate.cache.use_second_level_cache" value="false"/>
         <property name="jboss.entity.manager.factory.jndi.name" value="java:/RegisterUsersEntityManagerFactory"/>
      </properties>
   </persistence-unit>

</persistence>
[/XML]

Ich weiß nun nicht mehr weiter. Habe mich bei meiner Ausführung stark an das Buch "JBoss Seam" aus dem MITP-Verlag gehalten (Autoren: Michael Juntao Yuan & Thomas Heute).


Hat jemand dieses Verhalten schon mal gesehen und kann mir einen kleinen Tipp geben?  Wenn ich was vergessen habe sollte zu posten, kommt gern und prompt nach...


Vielen Dank schon mal

Thomas


----------



## tagedieb (11. Dez 2010)

Vielleich hilft das hier weiter...


----------



## thommy.s (11. Dez 2010)

...leider nicht, kenne ich schon, hat mir aber leider keine Antwort auf meine Frage gegeben. Trotzdem Danke.


----------



## thommy.s (11. Dez 2010)

Um noch weitere Informationen zu geben, ich entwickel' in Eclipse 3.6, nutze Seam 2.2 und deploye auf den JBoss 5.1.


----------

