Null entity manager
pedalshoe Jun 30, 2009 8:32 PMI feel like I'm going backwards here because I'm really trying to solve a different problem. The entityManager is always null at the point I need it. I'm creating a seam application in an ear file.
seam 2.1.2, jbossAS 4.2.3 is my environment.
Any help is greatly appreciated.
1. components.xml contains:
<persistence:managed-persistence-context name="entityManager" auto-create="true" persistence-unit-jndi-name="java:/myDBEntityManagerFactory"/> <security:identity authenticate-method="#{authenticator.authenticate}" remember-me="true"/>
2. persistence.xml contains:
<persistence version="1.0" 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"> <persistence-unit name="myDB" transaction-type="JTA"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:myDS</jta-data-source> <class>beans.Language</class> <exclude-unlisted-classes>true</exclude-unlisted-classes> <properties> <property name="hibernate.show_sql" value="true"/> <property name="hibernate.format_sql" value="true"/> <property name="hibernate.use_sql_comments" value="true"/> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/> <property name="jboss.entity.manager.factory.jndi.name" value="java:/myDBEntityManagerFactory"/> </properties> </persistence-unit> </persistence>
3: After I authenticate using the authenticate-method specified in components.xml I load a xhtml page that has a bean that injects the entityManager:
@Name("extendedTableBean") @Scope(ScopeType.CONVERSATION) public class ExtendedTableBean implements Serializable { @In EntityManager entityManager; @DataModel("languages") private List<Language> languages; // the data @Factory("languages") public void getLanguages() { if (entityManager == null) { System.err.println("ExtendedTableBean.getLanguages() entityManager is null"); } else { Query q = entityManager.createQuery("select L from Language"); languages = q.getResultList(); System.out.println("Languages len=" + languages.size() + " languages=" + languages.toArray()); } } @DataModelSelection private Language selectedLanguage; // the user selected language : :
4. at the time this bean is needed for the page the entityManager is always null at the @In annotation before I actually use the entityManager. The entityManager is set for auto-create true in components.xml but I still get the following exception:
14:05:22,140 ERROR [STDERR] Jun 30, 2009 2:05:22 PM com.sun.facelets.FaceletViewHandler handleRenderException SEVERE: Error Rendering View[/acct/index.xhtml] org.jboss.seam.RequiredException: @In attribute requires non-null value: extendedTableBean.entityManager at org.jboss.seam.Component.getValueToInject(Component.java:2335) at org.jboss.seam.Component.injectAttributes(Component.java:1736) at org.jboss.seam.Component.inject(Component.java:1554) at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
Any help is greatly appreciated.
Thank you,
-Christopher