Re: [Resin-interest] How to make this simplest CanDI work ?
smallufo wrote: I can now pinpoint the error , It's because I declare the PersistenceContextType to PersistenceContextType.EXTENDED !!! I don't know why resin cannot initialize EXTENDED PersistenceContext Because extended is only allowed when it's integrated with a stateful session bean and we haven't finished that part of EJB yet. (I've never been certain that extended is a good idea. With connection pooling, the normal transaction should be equivalent.) -- Scott Maybe caucho should look into the PersistenceContextGenerator.java , create() method try { if (PersistenceContextType.EXTENDED.equals(_type)) { _manager = create(EntityManager.class, new AnnotationLiteralJpaPersistenceContext() { public String value() { return _unitName; } public boolean extended() { return true; } }); } 2010/3/22 smallufo small...@gmail.com mailto:small...@gmail.com After a whole day work (but in vain) , I modified my code : I take off all hibernate-related settings/libraries from persistence.xml and maven dependencies , I just want to first use resin's Amber to test whether CanDI works... This is database settings in resin-web.xml : database jndi-name=jdbc/mining driver type=com.mysql.jdbc.Driver urljdbc:mysql://db/mining?useUnicode=trueamp;characterEncoding=UTF8/url useradm/user passwordpwd/password /driver max-connections100/max-connections /database This is persistence.xml : persistence xmlns=http://java.sun.com/xml/ns/persistence; version=1.0 persistence-unit name=mining transaction-type=RESOURCE_LOCAL non-jta-data-sourcejdbc/mining/non-jta-data-source classfoo.Person/class /properties /persistence-unit /persistence When resin inits , I can see Amber successfully get the connection , and build the connection pool (ManagedPoolItem) . But I still cannot get PersonDao's implementation , it seems resin cannot successfully create the PersistenceContext , here is the FINER log dump : WebApp[http://test.smallufo.com/testapp-1] map (uri:/hello - hello) Dispatch '/hello' to AccessLogFilterChain[http://test.smallufo.com/testapp-1, next=WebAppFilterChain[http://test.smallufo.com/testapp-1, next=ServletFilterChain[hello]]] com.caucho.config.ConfigException: foo.HelloServlet.personDao: foo.PersonDaoImpl.entityManager java.lang.NullPointerException at com.caucho.config.ConfigException.create(ConfigException.java:99) at com.caucho.config.ConfigException.create(ConfigException.java:125) at com.caucho.config.inject.InjectionTargetImpl$FieldInjectProgram.inject(InjectionTargetImpl.java:811) at com.caucho.config.inject.InjectionTargetImpl.inject(InjectionTargetImpl.java:266) at com.caucho.server.dispatch.ServletConfigImpl.createServletImpl(ServletConfigImpl.java:1260) at com.caucho.server.dispatch.ServletConfigImpl.createServlet(ServletConfigImpl.java:1142) at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:98) at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:183) at com.caucho.server.webapp.AccessLogFilterChain.doFilter(AccessLogFilterChain.java:103) at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:286) at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:775) at com.caucho.server.connection.TcpConnection.dispatchRequest(TcpConnection.java:600) at com.caucho.server.connection.TcpConnection.handleRequestsImpl(TcpConnection.java:566) at com.caucho.server.connection.TcpConnection.handleRequests(TcpConnection.java:519) at com.caucho.server.connection.TcpConnection$AcceptTask.doTask(TcpConnection.java:1100) at com.caucho.server.connection.TcpConnection$ConnectionReadTask.runThread(TcpConnection.java:1037) at com.caucho.server.connection.TcpConnection$AcceptTask.run(TcpConnection.java:1068) at com.caucho.util.ThreadPool$PoolThread.runTasks(ThreadPool.java:901) at com.caucho.util.ThreadPool$PoolThread.run(ThreadPool.java:866) Caused by: com.caucho.config.ConfigException: foo.PersonDaoImpl.entityManager java.lang.NullPointerException at com.caucho.config.ConfigException.create(ConfigException.java:102) at com.caucho.config.j2ee.PersistenceContextGenerator.create(PersistenceContextGenerator.java:121) at
Re: [Resin-interest] How to make this simplest CanDI work ?
After a whole day work (but in vain) , I modified my code : I take off all hibernate-related settings/libraries from persistence.xml and maven dependencies , I just want to first use resin's Amber to test whether CanDI works... This is database settings in resin-web.xml : database jndi-name=jdbc/mining driver type=com.mysql.jdbc.Driver urljdbc:mysql://db/mining?useUnicode=trueamp;characterEncoding=UTF8/url useradm/user passwordpwd/password /driver max-connections100/max-connections /database This is persistence.xml : persistence xmlns=http://java.sun.com/xml/ns/persistence; version=1.0 persistence-unit name=mining transaction-type=RESOURCE_LOCAL non-jta-data-sourcejdbc/mining/non-jta-data-source classfoo.Person/class /properties /persistence-unit /persistence When resin inits , I can see Amber successfully get the connection , and build the connection pool (ManagedPoolItem) . But I still cannot get PersonDao's implementation , it seems resin cannot successfully create the PersistenceContext , here is the FINER log dump : WebApp[http://test.smallufo.com/testapp-1] map (uri:/hello - hello) Dispatch '/hello' to AccessLogFilterChain[http://test.smallufo.com/testapp-1, next=WebAppFilterChain[http://test.smallufo.com/testapp-1, next=ServletFilterChain[hello]]] com.caucho.config.ConfigException: foo.HelloServlet.personDao: foo.PersonDaoImpl.entityManager java.lang.NullPointerException at com.caucho.config.ConfigException.create(ConfigException.java:99) at com.caucho.config.ConfigException.create(ConfigException.java:125) at com.caucho.config.inject.InjectionTargetImpl$FieldInjectProgram.inject(InjectionTargetImpl.java:811) at com.caucho.config.inject.InjectionTargetImpl.inject(InjectionTargetImpl.java:266) at com.caucho.server.dispatch.ServletConfigImpl.createServletImpl(ServletConfigImpl.java:1260) at com.caucho.server.dispatch.ServletConfigImpl.createServlet(ServletConfigImpl.java:1142) at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:98) at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:183) at com.caucho.server.webapp.AccessLogFilterChain.doFilter(AccessLogFilterChain.java:103) at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:286) at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:775) at com.caucho.server.connection.TcpConnection.dispatchRequest(TcpConnection.java:600) at com.caucho.server.connection.TcpConnection.handleRequestsImpl(TcpConnection.java:566) at com.caucho.server.connection.TcpConnection.handleRequests(TcpConnection.java:519) at com.caucho.server.connection.TcpConnection$AcceptTask.doTask(TcpConnection.java:1100) at com.caucho.server.connection.TcpConnection$ConnectionReadTask.runThread(TcpConnection.java:1037) at com.caucho.server.connection.TcpConnection$AcceptTask.run(TcpConnection.java:1068) at com.caucho.util.ThreadPool$PoolThread.runTasks(ThreadPool.java:901) at com.caucho.util.ThreadPool$PoolThread.run(ThreadPool.java:866) Caused by: com.caucho.config.ConfigException: foo.PersonDaoImpl.entityManager java.lang.NullPointerException at com.caucho.config.ConfigException.create(ConfigException.java:102) at com.caucho.config.j2ee.PersistenceContextGenerator.create(PersistenceContextGenerator.java:121) at com.caucho.config.program.FieldGeneratorProgram.inject(FieldGeneratorProgram.java:84) at com.caucho.config.inject.InjectionTargetImpl$FieldHandlerProgram.inject(InjectionTargetImpl.java:860) at com.caucho.config.inject.InjectionTargetImpl.inject(InjectionTargetImpl.java:266) at com.caucho.config.inject.ManagedBeanImpl.create(ManagedBeanImpl.java:149) at com.caucho.config.inject.InjectManager.getInstanceRec(InjectManager.java:1347) at com.caucho.config.inject.InjectManager.getReference(InjectManager.java:1311) at com.caucho.config.inject.InjectManager.getInjectableReference(InjectManager.java:1509) at com.caucho.config.inject.InjectionTargetImpl$FieldInjectProgram.inject(InjectionTargetImpl.java:807) ... 16 more Caused by: java.lang.NullPointerException at com.caucho.config.inject.InjectManager.getInstanceRec(InjectManager.java:1337) at com.caucho.config.inject.InjectManager.getReference(InjectManager.java:1311) at com.caucho.config.j2ee.WebBeanGenerator.create(WebBeanGenerator.java:66) at com.caucho.config.j2ee.PersistenceContextGenerator.create(PersistenceContextGenerator.java:108) ... 24 more Http[5] HTTP/1.1 500 Internal Server Error I've stuck with this problem for days , but cannot find an answer ... I'm very appreciated if somebody helps me... thanks. I am using Resin (non-Pro) 4.0.5 ___ resin-interest mailing list resin-interest@caucho.com
Re: [Resin-interest] How to make this simplest CanDI work ?
I can now pinpoint the error , It's because I declare the PersistenceContextType to PersistenceContextType.EXTENDED !!! I don't know why resin cannot initialize EXTENDED PersistenceContext Maybe caucho should look into the PersistenceContextGenerator.java , create() method try { if (PersistenceContextType.EXTENDED.equals(_type)) { _manager = create(EntityManager.class, new AnnotationLiteralJpaPersistenceContext() { public String value() { return _unitName; } public boolean extended() { return true; } }); } 2010/3/22 smallufo small...@gmail.com After a whole day work (but in vain) , I modified my code : I take off all hibernate-related settings/libraries from persistence.xml and maven dependencies , I just want to first use resin's Amber to test whether CanDI works... This is database settings in resin-web.xml : database jndi-name=jdbc/mining driver type=com.mysql.jdbc.Driver urljdbc:mysql://db/mining?useUnicode=trueamp;characterEncoding=UTF8/url useradm/user passwordpwd/password /driver max-connections100/max-connections /database This is persistence.xml : persistence xmlns=http://java.sun.com/xml/ns/persistence; version=1.0 persistence-unit name=mining transaction-type=RESOURCE_LOCAL non-jta-data-sourcejdbc/mining/non-jta-data-source classfoo.Person/class /properties /persistence-unit /persistence When resin inits , I can see Amber successfully get the connection , and build the connection pool (ManagedPoolItem) . But I still cannot get PersonDao's implementation , it seems resin cannot successfully create the PersistenceContext , here is the FINER log dump : WebApp[http://test.smallufo.com/testapp-1] map (uri:/hello - hello) Dispatch '/hello' to AccessLogFilterChain[ http://test.smallufo.com/testapp-1, next=WebAppFilterChain[ http://test.smallufo.com/testapp-1, next=ServletFilterChain[hello]]] com.caucho.config.ConfigException: foo.HelloServlet.personDao: foo.PersonDaoImpl.entityManager java.lang.NullPointerException at com.caucho.config.ConfigException.create(ConfigException.java:99) at com.caucho.config.ConfigException.create(ConfigException.java:125) at com.caucho.config.inject.InjectionTargetImpl$FieldInjectProgram.inject(InjectionTargetImpl.java:811) at com.caucho.config.inject.InjectionTargetImpl.inject(InjectionTargetImpl.java:266) at com.caucho.server.dispatch.ServletConfigImpl.createServletImpl(ServletConfigImpl.java:1260) at com.caucho.server.dispatch.ServletConfigImpl.createServlet(ServletConfigImpl.java:1142) at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:98) at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:183) at com.caucho.server.webapp.AccessLogFilterChain.doFilter(AccessLogFilterChain.java:103) at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:286) at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:775) at com.caucho.server.connection.TcpConnection.dispatchRequest(TcpConnection.java:600) at com.caucho.server.connection.TcpConnection.handleRequestsImpl(TcpConnection.java:566) at com.caucho.server.connection.TcpConnection.handleRequests(TcpConnection.java:519) at com.caucho.server.connection.TcpConnection$AcceptTask.doTask(TcpConnection.java:1100) at com.caucho.server.connection.TcpConnection$ConnectionReadTask.runThread(TcpConnection.java:1037) at com.caucho.server.connection.TcpConnection$AcceptTask.run(TcpConnection.java:1068) at com.caucho.util.ThreadPool$PoolThread.runTasks(ThreadPool.java:901) at com.caucho.util.ThreadPool$PoolThread.run(ThreadPool.java:866) Caused by: com.caucho.config.ConfigException: foo.PersonDaoImpl.entityManager java.lang.NullPointerException at com.caucho.config.ConfigException.create(ConfigException.java:102) at com.caucho.config.j2ee.PersistenceContextGenerator.create(PersistenceContextGenerator.java:121) at com.caucho.config.program.FieldGeneratorProgram.inject(FieldGeneratorProgram.java:84) at com.caucho.config.inject.InjectionTargetImpl$FieldHandlerProgram.inject(InjectionTargetImpl.java:860) at com.caucho.config.inject.InjectionTargetImpl.inject(InjectionTargetImpl.java:266) at com.caucho.config.inject.ManagedBeanImpl.create(ManagedBeanImpl.java:149) at com.caucho.config.inject.InjectManager.getInstanceRec(InjectManager.java:1347) at com.caucho.config.inject.InjectManager.getReference(InjectManager.java:1311) at com.caucho.config.inject.InjectManager.getInjectableReference(InjectManager.java:1509) at com.caucho.config.inject.InjectionTargetImpl$FieldInjectProgram.inject(InjectionTargetImpl.java:807) ...
[Resin-interest] How to make this simplest CanDI work ?
I am new to CanDI , I want to migrate my spring app to JavaEE6 , but having a lot of troubles in Resin (4.0.5) CanDI : There is no working sample in the resin site , most are outdated ... Here is my very basic sample , just JPA 2 and a Servlet : public interface PersonDao { public Person get(long id); } public class PersonDaoImpl implements PersonDao , Serializable { @PersistenceContext(unitName = mining, type = PersistenceContextType.EXTENDED) EntityManager em; @Override public Person get(long id) { return em.find(Person.class , id); } } public class HelloServlet extends HttpServlet { @javax.inject.Inject private PersonDao personDao; @Override protected void doGet(HttpServletRequest hreq, HttpServletResponse hres) throws ServletException, IOException { PrintWriter out = hres.getWriter(); System.out.println(personDao = + personDao); // outputs Null Person p = personDao.get(1L); //NPE , personDao is not injected out.println(Hello, world! , person = + p); out.close(); } } persistence.xml ?xml version=1.0 encoding=UTF-8? persistence xmlns=http://java.sun.com/xml/ns/persistence; version=1.0 persistence-unit name=mining transaction-type=RESOURCE_LOCAL providerorg.hibernate.ejb.HibernatePersistence/provider classfoo.Person/class properties property name=hibernate.dialect value=org.hibernate.dialect.MySQLDialect / property name=hibernate.cache.provider_class value=org.hibernate.cache.EhCacheProvider / property name=hibernate.show_sql value=true / property name=hibernate.format_sql value=true / property name=javax.persistence.jdbc.driver value=com.mysql.jdbc.Driver / property name=javax.persistence.jdbc.user value=adm / property name=javax.persistence.jdbc.password value=pwd / property name=javax.persistence.jdbc.url value=jdbc:mysql://db/mining?useUnicode=trueamp;characterEncoding=UTF8 / /properties /persistence-unit /persistence META-INF/beans.xml beans xmlns=http://java.sun.com/xml/ns/javaee; /beans my environment : dependency groupIdorg.hibernate/groupId artifactIdhibernate-core/artifactId version3.5.0-CR-2/version /dependency dependency groupIdorg.hibernate.javax.persistence/groupId artifactIdhibernate-jpa-2.0-api/artifactId version1.0.0-CR-1/version scopeprovided/scope /dependency This is a very basic Dao + JPA pattern , but I cannot find how to inject the PersonDaoImpl to the Dao in the Servlet , Can somebody give me a hint ? Thanks in advenced ! BTW , Is META-INF/beans.xml defined in the JavaEE spec ? What's the relation with beans.xml and resin-web.xml ? ___ resin-interest mailing list resin-interest@caucho.com http://maillist.caucho.com/mailman/listinfo/resin-interest
Re: [Resin-interest] How to make this simplest CanDI work ?
BTW , Is META-INF/beans.xml defined in the JavaEE spec ? What's the relation with beans.xml and resin-web.xml ? yes, beans.xml is part of JSR-299. resin-web.xml has the same role as web.xml, it is processed by Resin after web.xml. You can place resin specific / non-standard configuration into resin-web.xml. smallufo írta: I am new to CanDI , I want to migrate my spring app to JavaEE6 , but having a lot of troubles in Resin (4.0.5) CanDI : There is no working sample in the resin site , most are outdated ... Here is my very basic sample , just JPA 2 and a Servlet : public interface PersonDao { public Person get(long id); } public class PersonDaoImpl implements PersonDao , Serializable { @PersistenceContext(unitName = mining, type = PersistenceContextType.EXTENDED) EntityManager em; @Override public Person get(long id) { return em.find(Person.class , id); } } public class HelloServlet extends HttpServlet { @javax.inject.Inject private PersonDao personDao; @Override protected void doGet(HttpServletRequest hreq, HttpServletResponse hres) throws ServletException, IOException { PrintWriter out = hres.getWriter(); System.out.println(personDao = + personDao); // outputs Null Person p = personDao.get(1L); //NPE , personDao is not injected out.println(Hello, world! , person = + p); out.close(); } } persistence.xml ?xml version=1.0 encoding=UTF-8? persistence xmlns=http://java.sun.com/xml/ns/persistence; version=1.0 persistence-unit name=mining transaction-type=RESOURCE_LOCAL providerorg.hibernate.ejb.HibernatePersistence/provider classfoo.Person/class properties property name=hibernate.dialect value=org.hibernate.dialect.MySQLDialect / property name=hibernate.cache.provider_class value=org.hibernate.cache.EhCacheProvider / property name=hibernate.show_sql value=true / property name=hibernate.format_sql value=true / property name=javax.persistence.jdbc.driver value=com.mysql.jdbc.Driver / property name=javax.persistence.jdbc.user value=adm / property name=javax.persistence.jdbc.password value=pwd / property name=javax.persistence.jdbc.url value=jdbc:mysql://db/mining?useUnicode=trueamp;characterEncoding=UTF8 / /properties /persistence-unit /persistence META-INF/beans.xml beans xmlns=http://java.sun.com/xml/ns/javaee; /beans my environment : dependency groupIdorg.hibernate/groupId artifactIdhibernate-core/artifactId version3.5.0-CR-2/version /dependency dependency groupIdorg.hibernate.javax.persistence/groupId artifactIdhibernate-jpa-2.0-api/artifactId version1.0.0-CR-1/version scopeprovided/scope /dependency This is a very basic Dao + JPA pattern , but I cannot find how to inject the PersonDaoImpl to the Dao in the Servlet , Can somebody give me a hint ? Thanks in advenced ! BTW , Is META-INF/beans.xml defined in the JavaEE spec ? What's the relation with beans.xml and resin-web.xml ? ___ resin-interest mailing list resin-interest@caucho.com http://maillist.caucho.com/mailman/listinfo/resin-interest ___ resin-interest mailing list resin-interest@caucho.com http://maillist.caucho.com/mailman/listinfo/resin-interest
Re: [Resin-interest] How to make this simplest CanDI work ?
Thank you ... Back to the topic .. Is there any example that shows injecting JPA entitymanager to the DaoImpl , and inject the DaoImpl (as a Dao interface) to the Servlet ? 2010/3/21 Hontvári József hontv...@flyordie.com BTW , Is META-INF/beans.xml defined in the JavaEE spec ? What's the relation with beans.xml and resin-web.xml ? yes, beans.xml is part of JSR-299. resin-web.xml has the same role as web.xml, it is processed by Resin after web.xml. You can place resin specific / non-standard configuration into resin-web.xml. smallufo írta: I am new to CanDI , I want to migrate my spring app to JavaEE6 , but having a lot of troubles in Resin (4.0.5) CanDI : There is no working sample in the resin site , most are outdated ... Here is my very basic sample , just JPA 2 and a Servlet : public interface PersonDao { public Person get(long id); } public class PersonDaoImpl implements PersonDao , Serializable { @PersistenceContext(unitName = mining, type = PersistenceContextType.EXTENDED) EntityManager em; @Override public Person get(long id) { return em.find(Person.class , id); } } public class HelloServlet extends HttpServlet { @javax.inject.Inject private PersonDao personDao; @Override protected void doGet(HttpServletRequest hreq, HttpServletResponse hres) throws ServletException, IOException { PrintWriter out = hres.getWriter(); System.out.println(personDao = + personDao); // outputs Null Person p = personDao.get(1L); //NPE , personDao is not injected out.println(Hello, world! , person = + p); out.close(); } } persistence.xml ?xml version=1.0 encoding=UTF-8? persistence xmlns=http://java.sun.com/xml/ns/persistence; version=1.0 persistence-unit name=mining transaction-type=RESOURCE_LOCAL providerorg.hibernate.ejb.HibernatePersistence/provider classfoo.Person/class properties property name=hibernate.dialect value=org.hibernate.dialect.MySQLDialect / property name=hibernate.cache.provider_class value=org.hibernate.cache.EhCacheProvider / property name=hibernate.show_sql value=true / property name=hibernate.format_sql value=true / property name=javax.persistence.jdbc.driver value=com.mysql.jdbc.Driver / property name=javax.persistence.jdbc.user value=adm / property name=javax.persistence.jdbc.password value=pwd / property name=javax.persistence.jdbc.url value=jdbc:mysql://db/mining?useUnicode=trueamp;characterEncoding=UTF8 / /properties /persistence-unit /persistence META-INF/beans.xml beans xmlns=http://java.sun.com/xml/ns/javaee; /beans my environment : dependency groupIdorg.hibernate/groupId artifactIdhibernate-core/artifactId version3.5.0-CR-2/version /dependency dependency groupIdorg.hibernate.javax.persistence/groupId artifactIdhibernate-jpa-2.0-api/artifactId version1.0.0-CR-1/version scopeprovided/scope /dependency This is a very basic Dao + JPA pattern , but I cannot find how to inject the PersonDaoImpl to the Dao in the Servlet , Can somebody give me a hint ? Thanks in advenced ! BTW , Is META-INF/beans.xml defined in the JavaEE spec ? What's the relation with beans.xml and resin-web.xml ? -- ___ resin-interest mailing listresin-inter...@caucho.comhttp://maillist.caucho.com/mailman/listinfo/resin-interest ___ resin-interest mailing list resin-interest@caucho.com http://maillist.caucho.com/mailman/listinfo/resin-interest ___ resin-interest mailing list resin-interest@caucho.com http://maillist.caucho.com/mailman/listinfo/resin-interest