hi; I am using seam with tomcate and icefaces the problem is when I inject entity manager in component bean it works well but if put it in generic DAO it returns null my code is like that:
this the bean
@Scope(ScopeType.PAGE)
@Name("TestBean")
public class TestBean {
public void test(ActionEvent actionEvent) {
Roles entity = new Roles();
entity.setName("cons");
RolesDao dao = new RolesDao();
dao.emPrisit(entity);
}
}
DAO
public class RolesDao {
@In
EntityManager em;
public void emPrisit(Roles entity) {
em.persist(entity);
}
}
Component.xml
<persistence:entity-manager-factory name="bookingDatabase"/>
<persistence:managed-persistence-context name="em"
auto-create="true"
entity-manager-factory="#{bookingDatabase}"/>
persistence.xml
<persistence-unit name="bookingDatabase"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence </provider>
<jta-data-source>java:comp/env/AP</jta-data-source>
<properties>
<property name="transaction.flush_before_completion" value="true" />
<property name="transaction.factory_class"
value="org.hibernate.transaction.JDBCTransactionFactory" />
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<!--
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
-->
</properties>
</persistence-unit>
if I inject entitymanger in bean not dao it runs well the second problem when I add this annotation before entitymanger
@In
@PersistenceContext(type = PersistenceContextType.EXTENDED)
EntityManager em;
it give this exception
caused by: java.lang.IllegalArgumentException: @PersistenceContext may only be used on session bean or message driven bean components: TestBean
at org.jboss.seam.Component.checkPersistenceContextForComponentType(Component.java:901)
at org.jboss.seam.Component.scanField(Component.java:877)
at org.jboss.seam.Component.initMembers(Component.java:557)
at org.jboss.seam.Component.<init>(Component.java:244)
at org.jboss.seam.Component.<init>(Component.java:205)
at org.jboss.seam.init.Initialization.addComponent(Initialization.java:1186)
... 13 more