Hi Leon, Injection via @Inject only works in pages, components, and mixins. If you need to inject into a service, you can use either constructor or setter injection. If you use constructor injection then you can use auto binding to bind your dao implementation, and it will jsut work. Otherwise you can provide a builder method and build it manually.
If you haven't already, read up on how t5-ioc does binding: http://tapestry.apache.org/tapestry5/tapestry-ioc/module.html chris Leon Derks wrote: > I have added an JPA entity manager to my AppModule, in the same way > this is done for an HibernateSessionManager/Session in the > tapestry-hibernate project. > See the code below for some details. > > I inject this entity manager with the @Inject into my DAO object. > @Inject > private EntityManager entityManager > > In my DAO method I use the injected entityManager to build queries > like this: > entityManager.createNamedQuery("findProductsByCategory").setParameter("productCategory", > ProductCategory.Lamps).getResultList(); > > But the problem is that the entityManager is null. It seems that the > entityManager is not correctly injected into my DAO class. > Because when I use the entityManager directly in my Java Page class > and execute the same code, everything works well. > > Java Page code: > public void onActivate() { > // this results in an null pointer exception. > products = productDAO.findAllByCategory(ProductCategory.Lamps); > > //this is working. > products = > entityManager.createNamedQuery("findProductsByCategory").setParameter("productCategory", > ProductCategory.Lamps).getResultList(); > } > > What do I need to do so I can use my DAO classes? > > Leon > > > AppModule.java: > /** > * The JPAEnitityManagerService manages the entity manager on a > per-thread/per-request basis. A [EMAIL PROTECTED] > javax.persistence.EntityTransaction} is created > * initially, and is committed at the end of the request. > */ > @Scope(PERTHREAD_SCOPE) > public static JPAEntityManagerService build(PerthreadManager > perthreadManager) { > JPAEntityManagerServiceImpl jpaService = new > JPAEntityManagerServiceImpl(); > perthreadManager.addThreadCleanupListener(jpaService); > return jpaService; > > } > > public static EntityManager build(JPAEntityManagerService > jpaService, PropertyShadowBuilder propertyShadowBuilder) { > return propertyShadowBuilder.build(jpaService, "entityManager", > EntityManager.class); > } > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- http://thegodcode.net --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]