[jboss-user] [JBoss Seam] - Problems loading EntityManager in
wachtda
do-not-reply at jboss.com
Mon Feb 11 11:09:07 EST 2008
Hello together!
I'm trying to get the "Store your message in a database" example from the blog of Pete Muir working...
I noticed, that I have some problems with the EntityManger,
the EntityManager is always null!
Some hints?
Thanks Daniel
File: persistence.xml
| <persistence>
| <persistence-unit name="maxcontrol">
| <provider>org.hibernate.ejb.HibernatePersistence</provider>
| <jta-data-source>java:/maxcontrolDatasource</jta-data-source>
| <properties>
| <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
| <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
| <property name="hibernate.transaction.flush_before_completion" value="true"/>
| <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
| <property name="hibernate.show_sql" value="true"/>
| <property name="jboss.entity.manager.factory.jndi.name"
| value="java:/maxcontrolEntityManagerFactory" />
|
| </properties>
| </persistence-unit>
| </persistence>
|
File: components.xml
| <?xml version="1.0" encoding="UTF-8"?>
| <components xmlns="http://jboss.com/products/seam/components"
| xmlns:core="http://jboss.com/products/seam/core"
| xmlns:persistence="http://jboss.com/products/seam/persistence"
| xmlns:security="http://jboss.com/products/seam/security"
| xmlns:async="http://jboss.com/products/seam/async"
| xmlns:mail="http://jboss.com/products/seam/mail"
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
| xsi:schemaLocation=
| "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd
| http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd
| http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd
| http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
| http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.0.xsd">
|
|
| <core:init jndi-pattern="maxcontrol/#{ejbName}/local" debug="true"/>
|
| <core:manager conversation-timeout="120000"/>
|
| <persistence:managed-persistence-context name="entityManager"
| auto-create="true"
| persistence-unit-jndi-name="java:/maxcontrolEntityManagerFactory" />
|
| <!-- Loading Security-Settings -->
| <security:identity authenticate-method="#{authenticator.authenticate}" />
|
| <!-- Loading Mail-Settings -->
| <mail:mail-session host="localhost"
| port="25"
| debug="true"
| username=""
| password=""/>
|
| <!-- Loading Quartz-Settings -->
| <!-- <async:quartz-dispatcher /> -->
|
|
| </components>
|
File: DatabaseResourceLoader.java
| import java.util.Collections;
| import java.util.Enumeration;
| import java.util.List;
| import java.util.Locale;
| import java.util.ResourceBundle;
| import javax.persistence.EntityManager;
| import javax.persistence.NoResultException;
| import org.jboss.seam.Component;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.annotations.intercept.BypassInterceptors;
| import org.jboss.seam.core.ResourceLoader;
|
|
| /**
| * @author dwachter
| * @version 1.0
| * @created 07-Feb-2008 17:29:18
| */
| @BypassInterceptors
| @Name("org.jboss.seam.core.resourceLoader")
| public class DatabaseResourceLoader extends ResourceLoader {
|
| // Redefine how we load a resource bundle
| public ResourceBundle loadBundle(final String bundleName) {
| return new ResourceBundle() {
|
| public Enumeration<String> getKeys() {
| Locale locale = org.jboss.seam.core.Locale.instance();
| EntityManager entityManager = (EntityManager) Component.getInstance("myEntityManager");
| List resources = entityManager.createNamedQuery("keys")
| .setParameter("bundleName", bundleName)
| .setParameter("language", locale.getLanguage())
| .setParameter("country", locale.getCountry())
| .setParameter("variant", locale.getVariant())
| .getResultList();
| return Collections.enumeration(resources);
| }
|
| protected Object handleGetObject(String key) {
| Locale locale = org.jboss.seam.core.Locale.instance();
| EntityManager entityManager = (EntityManager) Component.getInstance("myEntityManager");
|
| // Check state of Entitymanager
| if(entityManager == null) {
| System.out.println("EM IS NULL!");
| }
| else {
| System.out.println("EM IS NOT NULL!");
| }
|
| try {
| return entityManager.createNamedQuery("value")
| .setParameter("bundleName", bundleName)
| .setParameter("language", locale.getLanguage())
| .setParameter("country", locale.getCountry())
| .setParameter("variant", locale.getVariant())
| .setParameter("key", key)
| .getSingleResult();
| } catch (NoResultException e) {
| return null;
| }
| }
|
| };
| }
| }
|
Console output:
| 16:52:39,818 INFO [STDOUT] EM IS NULL!
| 16:52:39,839 ERROR [SeamPhaseListener] uncaught exception
| javax.el.ELException: javax.ejb.EJBTransactionRolledbackException
| at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:333)
| at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:274)
| at org.jboss.el.parser.AstMethodSuffix.getValue(AstMethodSuffix.java:59)
| at org.jboss.el.parser.AstMethodSuffix.invoke(AstMethodSuffix.java:65)
| at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
| at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
| at org.jboss.seam.core.Expressions$2.invoke(Expressions.java:173)
| at org.jboss.seam.navigation.Pages.callAction(Pages.java:636)
| at org.jboss.seam.navigation.Pages.preRender(Pages.java:289)
| at org.jboss.seam.jsf.SeamPhaseListener.preRenderPage(SeamPhaseListener.java:549)
| at org.jboss.seam.jsf.SeamPhaseListener.beforeRenderResponse(SeamPhaseListener.java:460)
| at org.jboss.seam.jsf.SeamPhaseListener.beforeServletPhase(SeamPhaseListener.java:144)
| at org.jboss.seam.jsf.SeamPhaseListener.beforePhase(SeamPhaseListener.java:114)
| at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:222)
| at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
| at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
| at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
| at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
| at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:307)
| at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
| 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.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
| at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
| at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
| 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:141)
| at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
| at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
| at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
| at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
| 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:230)
| at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
| at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
| at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
| at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
| 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:157)
| at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
| at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
| at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:856)
| at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:566)
| at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1508)
| at java.lang.Thread.run(Thread.java:595)
| Caused by: javax.ejb.EJBTransactionRolledbackException
| at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:87)
| at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
| at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
| at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:240)
| at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:210)
| at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:84)
| at $Proxy661.testLocale(Unknown Source)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
| at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
| at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
| at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
| at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
| at org.javassist.tmp.java.lang.Object_$$_javassist_1.testLocale(Object_$$_javassist_1.java)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:329)
| ... 55 more
| Caused by: java.lang.NullPointerException
| at com.solarmax.maxcontrol.action.auth.DatabaseResourceLoader$1.handleGetObject(DatabaseResourceLoader.java:54)
| at java.util.ResourceBundle.getObject(ResourceBundle.java:319)
| at org.jboss.seam.core.SeamResourceBundle.handleGetObject(SeamResourceBundle.java:108)
| at java.util.ResourceBundle.getObject(ResourceBundle.java:319)
| at java.util.ResourceBundle.getString(ResourceBundle.java:285)
| at org.jboss.seam.international.Messages$1.get(Messages.java:60)
| at org.jboss.seam.international.Messages$1.get(Messages.java:102)
| at javax.el.MapELResolver.getValue(MapELResolver.java:51)
| at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
| at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:64)
| at org.jboss.el.parser.AstBracketSuffix.getValue(AstBracketSuffix.java:59)
| at org.jboss.el.parser.AstValue.getValue(AstValue.java:67)
| at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
| at org.jboss.seam.core.Expressions$1.getValue(Expressions.java:111)
| at org.jboss.seam.Component.getValueToInject(Component.java:2125)
| at org.jboss.seam.Component.injectAttributes(Component.java:1598)
| at org.jboss.seam.Component.inject(Component.java:1416)
| at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:45)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
| at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
| at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:26)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
| at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:27)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
| at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
| at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
| at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
| ... 88 more
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4128419#4128419
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4128419
More information about the jboss-user
mailing list