Re: [rules-users] Persistence.createEntityManagerFactory NullPointerException

2010-09-08 Thread liang
i had solve it.
In the Tomcat conf/context.xml or webapp/meta-inf/content.xml  Transaction
factory=bitronix.tm.BitronixUserTransactionObjectFactory /  its required
:

Context
Transaction factory=bitronix.tm.BitronixUserTransactionObjectFactory /
   Resource name=jdbc/mysql auth=Container type=javax.sql.DataSource
   maxActive=10 maxIdle=2 maxWait=1
logAbandoned=true
   username=root password=11
driverClassName=com.mysql.jdbc.Driver
   url=jdbc:mysql://localhost:3306/test/
/Context
webapp/web-inf/web.xml:
resource-env-ref
   resource-env-ref-namejdbc/mysql/resource-env-ref-name
   resource-env-ref-typejavax.sql.DataSource/resource-env-ref-type
 /resource-env-ref

thanks,everyone


在 2010年9月6日 上午10:40,liang zhuyx...@gmail.com写道:

 hi gustavo,

 has a big different between tomcat5.5 and tomcat6? According to your
 guide,i cannot bind JNDI,maybe i must set resource in tomcat
 conf/context.xml, i am confusing……can you  send a example to me?THS

 在 2010年9月3日 下午11:49,Gustavo Tenrreiro gust...@tenrreiro.com写道:

 If it helps at all; I spent almost a full week trying to get JPA  to
 work with Tomcat 5.5 + Hibernate + Bitronix and this is what I found.

 The instructions for Bitronix in
 http://docs.codehaus.org/display/BTM/Tomcat13 did not help me much.
 The datasource that gets created via the resource.properties could
 never be found.

 - So to get it to work, do deploy the Bitronix jar files into your
 server / context

 - In the Tomcat conf/context.xml I do have Transaction
 factory=bitronix.tm.BitronixUserTransactionObjectFactory / but I
 am not sure if it is required ( haven't tested removing it ).

 - In the web.xml I do have:

  resource-env-ref

  
 resource-env-ref-namejava:comp/env/jdbc/processInstanceDS/resource-env-ref-name
resource-env-ref-typejavax.sql.DataSource/resource-env-ref-type
  /resource-env-ref

 where jdbc/processInstanceDS is your jdbc/mysql

 - In the Hibernate persistence.xml I do have:

  property name=hibernate.transaction.manager_lookup_class
 value=org.hibernate.transaction.BTMTransactionManagerLookup /
   property name=hibernate.jndi.class
 value=bitronix.tm.jndi.BitronixInitialContextFactory /

 although I don't think it is using the jndi.class specified there, so
 the second line might be redundant.

 Then in my code I create the datasource by hand ( in a
 ServletContextListener ):

PoolingDataSource ds = new PoolingDataSource();
ds.setUniqueName( jdbc/processInstanceDS );
ds.setClassName(
 bitronix.tm.resource.jdbc.lrc.LrcXADataSource);
ds.setMaxPoolSize( 3 );
ds.setAllowLocalTransactions( true );

  
 ds.getDriverProperties().put(driverClassName,com.microsoft.sqlserver.jdbc.SQLServerDriver);
ds.getDriverProperties().put( user, xxx );
ds.getDriverProperties().put( password,
  );
ds.getDriverProperties().put( url,
 mySqlServerUrl... );

 replace the driverClassName, user, password, and url for your setup. I
 am using SQLServer, but I guess you are on MySql.

 After that the JPA stuff works, and persistence works as advertised.
 This is the only setup that worked for me. I tried creating the
 datasource from Spring but that didn't work either.

 Please let me know what you find out.

 Thanks


 2010/9/3 Pablo Nussembaum bau...@gmail.com:
  You need to configure bitronix[0] to provide JTA. Or use drools-spring
 that
  allows you to use drools-persisntece-jpa without JTA.
 
  [0] http://docs.codehaus.org/display/BTM/Tomcat13
  On 09/03/2010 08:53 AM, liang wrote:
 
  i found that tomcat 6 have not JTA,which server is able to persistence?
 
  在 2010年9月3日 下午12:02,liang zhuyx...@gmail.com写道:
 
  THS,Esteban,I found it which is resin's problem, so i replaced it to
  tomcat6, i got other questions:
 
   in my webapp webroot/meta-inf/content.xml:
  ?xml version=1.0 encoding=UTF-8?
  Context
Resource name=jdbc/mysql auth=Container
 type=javax.sql.DataSource
 maxActive=10 maxIdle=2 maxWait=1
  logAbandoned=true
 username=root password=11
  driverClassName=com.mysql.jdbc.Driver
 url=jdbc:mysql://localhost:3306/test/
  /Context
 
  webroot/web-inf/web.xml:
 
   resource-ref
descriptionDB Connection/description
res-ref-namejdbc/mysql/res-ref-name
res-typejavax.sql.DataSource/res-type
res-authContainer/res-auth
  /resource-ref
 
  webroot/meta-inf/persistence.xml:
 
  ?xml version=1.0 encoding=UTF-8 standalone=yes?
  persistence
  version=1.0
  xsi:schemaLocation=
  http://java.sun.com/xml/ns/persistence
   http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd
   http://java.sun.com/xml/ns/persistence/orm
   http://java.sun.com/xml/ns/persistence/orm_1_0.xsd;
  

Re: [rules-users] Persistence.createEntityManagerFactory NullPointerException

2010-09-05 Thread liang
hi gustavo,

has a big different between tomcat5.5 and tomcat6? According to your guide,i
cannot bind JNDI,maybe i must set resource in tomcat conf/context.xml, i am
confusing……can you  send a example to me?THS

在 2010年9月3日 下午11:49,Gustavo Tenrreiro gust...@tenrreiro.com写道:

 If it helps at all; I spent almost a full week trying to get JPA  to
 work with Tomcat 5.5 + Hibernate + Bitronix and this is what I found.

 The instructions for Bitronix in
 http://docs.codehaus.org/display/BTM/Tomcat13 did not help me much.
 The datasource that gets created via the resource.properties could
 never be found.

 - So to get it to work, do deploy the Bitronix jar files into your
 server / context

 - In the Tomcat conf/context.xml I do have Transaction
 factory=bitronix.tm.BitronixUserTransactionObjectFactory / but I
 am not sure if it is required ( haven't tested removing it ).

 - In the web.xml I do have:

  resource-env-ref

  
 resource-env-ref-namejava:comp/env/jdbc/processInstanceDS/resource-env-ref-name
resource-env-ref-typejavax.sql.DataSource/resource-env-ref-type
  /resource-env-ref

 where jdbc/processInstanceDS is your jdbc/mysql

 - In the Hibernate persistence.xml I do have:

  property name=hibernate.transaction.manager_lookup_class
 value=org.hibernate.transaction.BTMTransactionManagerLookup /
   property name=hibernate.jndi.class
 value=bitronix.tm.jndi.BitronixInitialContextFactory /

 although I don't think it is using the jndi.class specified there, so
 the second line might be redundant.

 Then in my code I create the datasource by hand ( in a
 ServletContextListener ):

PoolingDataSource ds = new PoolingDataSource();
ds.setUniqueName( jdbc/processInstanceDS );
ds.setClassName(
 bitronix.tm.resource.jdbc.lrc.LrcXADataSource);
ds.setMaxPoolSize( 3 );
ds.setAllowLocalTransactions( true );

  
 ds.getDriverProperties().put(driverClassName,com.microsoft.sqlserver.jdbc.SQLServerDriver);
ds.getDriverProperties().put( user, xxx );
ds.getDriverProperties().put( password, 
 );
ds.getDriverProperties().put( url,
 mySqlServerUrl... );

 replace the driverClassName, user, password, and url for your setup. I
 am using SQLServer, but I guess you are on MySql.

 After that the JPA stuff works, and persistence works as advertised.
 This is the only setup that worked for me. I tried creating the
 datasource from Spring but that didn't work either.

 Please let me know what you find out.

 Thanks


 2010/9/3 Pablo Nussembaum bau...@gmail.com:
  You need to configure bitronix[0] to provide JTA. Or use drools-spring
 that
  allows you to use drools-persisntece-jpa without JTA.
 
  [0] http://docs.codehaus.org/display/BTM/Tomcat13
  On 09/03/2010 08:53 AM, liang wrote:
 
  i found that tomcat 6 have not JTA,which server is able to persistence?
 
  在 2010年9月3日 下午12:02,liang zhuyx...@gmail.com写道:
 
  THS,Esteban,I found it which is resin's problem, so i replaced it to
  tomcat6, i got other questions:
 
   in my webapp webroot/meta-inf/content.xml:
  ?xml version=1.0 encoding=UTF-8?
  Context
Resource name=jdbc/mysql auth=Container
 type=javax.sql.DataSource
 maxActive=10 maxIdle=2 maxWait=1
  logAbandoned=true
 username=root password=11
  driverClassName=com.mysql.jdbc.Driver
 url=jdbc:mysql://localhost:3306/test/
  /Context
 
  webroot/web-inf/web.xml:
 
   resource-ref
descriptionDB Connection/description
res-ref-namejdbc/mysql/res-ref-name
res-typejavax.sql.DataSource/res-type
res-authContainer/res-auth
  /resource-ref
 
  webroot/meta-inf/persistence.xml:
 
  ?xml version=1.0 encoding=UTF-8 standalone=yes?
  persistence
  version=1.0
  xsi:schemaLocation=
  http://java.sun.com/xml/ns/persistence
   http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd
   http://java.sun.com/xml/ns/persistence/orm
   http://java.sun.com/xml/ns/persistence/orm_1_0.xsd;
  xmlns:orm=http://java.sun.com/xml/ns/persistence/orm;
  xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
  xmlns=http://java.sun.com/xml/ns/persistence;
 
   !--persistence-unit name=ProcessService
jta-data-sourcejava:/DefaultDS/jta-data-source
properties
 property name=hibernate.hbm2ddl.auto value=create-drop/
/properties
   /persistence-unit--
 
  persistence-unit name=org.drools.persistence.jpa
  transaction-type=JTA
  providerorg.hibernate.ejb.HibernatePersistence/provider
  jta-data-sourcejava:comp/env/jdbc/mysql/jta-data-source
  classorg.drools.persistence.session.SessionInfo/class
 
  classorg.drools.persistence.processinstance.ProcessInstanceInfo/class
 
 
 classorg.drools.persistence.processinstance.ProcessInstanceEventInfo/class
  

Re: [rules-users] Persistence.createEntityManagerFactory NullPointerException

2010-09-03 Thread liang
i found that tomcat 6 have not JTA,which server is able to persistence?

在 2010年9月3日 下午12:02,liang zhuyx...@gmail.com写道:

 THS,Esteban,I found it which is resin's problem, so i replaced it to
 tomcat6, i got other questions:

  in my webapp webroot/meta-inf/content.xml:
 ?xml version=1.0 encoding=UTF-8?
 Context
   Resource name=jdbc/mysql auth=Container type=javax.sql.DataSource
maxActive=10 maxIdle=2 maxWait=1
 logAbandoned=true
username=root password=11
 driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/test/
 /Context

 webroot/web-inf/web.xml:

  resource-ref
   descriptionDB Connection/description
   res-ref-namejdbc/mysql/res-ref-name
   res-typejavax.sql.DataSource/res-type
   res-authContainer/res-auth
 /resource-ref

 webroot/meta-inf/persistence.xml:

 ?xml version=1.0 encoding=UTF-8 standalone=yes?
 persistence
 version=1.0
 xsi:schemaLocation=
 http://java.sun.com/xml/ns/persistence
  http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd
  http://java.sun.com/xml/ns/persistence/orm
  http://java.sun.com/xml/ns/persistence/orm_1_0.xsd;
 xmlns:orm=http://java.sun.com/xml/ns/persistence/orm;
 xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
 xmlns=http://java.sun.com/xml/ns/persistence;

  !--persistence-unit name=ProcessService
   jta-data-sourcejava:/DefaultDS/jta-data-source
   properties
property name=hibernate.hbm2ddl.auto value=create-drop/
   /properties
  /persistence-unit--


 persistence-unit name=org.drools.persistence.jpa
 transaction-type=JTA
 providerorg.hibernate.ejb.HibernatePersistence/provider
 jta-data-sourcejava:comp/env/jdbc/mysql/jta-data-source
 classorg.drools.persistence.session.SessionInfo/class
  classorg.drools.persistence.processinstance.ProcessInstanceInfo/class

 classorg.drools.persistence.processinstance.ProcessInstanceEventInfo/class
 classorg.drools.persistence.processinstance.WorkItemInfo/class


 properties
 property name=hibernate.dialect
 value=org.hibernate.dialect.MySQLDialect/
 property name=hibernate.max_fetch_depth value=3/
 property name=hibernate.hbm2ddl.auto value=create /
 property name=hibernate.show_sql value=true /
 property name=hibernate.transaction.manager_lookup_class
 value=org.hibernate.transaction.BTMTransactionManagerLookup /
 /properties
 /persistence-unit

 /persistence

 webroot/testJNDI.jsp:

 %@ page import='java.sql.*, javax.sql.*, javax.naming.*' %
 %
 Context ic = new InitialContext();
 DataSource ds = (DataSource) ic.lookup(java:comp/env/jdbc/mysql);

 Connection conn = ds.getConnection();

 try {
   Statement stmt = conn.createStatement();
   ResultSet rs = stmt.executeQuery(select * from test);
   while (rs.next()) { %
 %= rs.getString(1) % %= rs.getString(2) %br%
   }
 } finally {
   conn.close();
 }
 %

 webroot/testDroolsFlow.jsp:

 %@ page import='java.sql.*, javax.sql.*, javax.naming.*,com.abc.*' %
 %
 VdcService.exec();
 %

 run the testJNDI.jsp,its OK.when i run testDroolsFlow.jsp, appears this
 exception:

 java.lang.RuntimeException: Could not commit session
 at
 org.drools.persistence.session.SingleSessionCommandService.init(SingleSessionCommandService.java:119)
 at
 org.drools.persistence.jpa.impl.JPAKnowledgeServiceProviderImpl.newStatefulKnowledgeSession(JPAKnowledgeServiceProviderImpl.java:44)
 at
 org.drools.persistence.jpa.JPAKnowledgeService.newStatefulKnowledgeSession(JPAKnowledgeService.java:93)
 at com.abc.VdcService.exec(VdcService.java:39)
 at
 org.apache.jsp._testDroolsFlow_jsp._jspService(_testDroolsFlow_jsp.java:60)
 at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 at
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
 at
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
 at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 at
 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 at
 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at
 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
 at
 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
 at
 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
 at
 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
 at
 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
 at
 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
 at
 

Re: [rules-users] Persistence.createEntityManagerFactory NullPointerException

2010-09-03 Thread Michael Anstis
Do you really need a JTA transaction?

Can you not re-configure your persistence unit to use a RESOURCE_LOCAL
transaction?

Googling shows you're not alone with wanting (but not necessarily needing)
JTA in Tomcat...

2010/9/3 liang zhuyx...@gmail.com

 i found that tomcat 6 have not JTA,which server is able to persistence?

 在 2010年9月3日 下午12:02,liang zhuyx...@gmail.com写道:

 THS,Esteban,I found it which is resin's problem, so i replaced it to
 tomcat6, i got other questions:

  in my webapp webroot/meta-inf/content.xml:
 ?xml version=1.0 encoding=UTF-8?
 Context
   Resource name=jdbc/mysql auth=Container type=javax.sql.DataSource
maxActive=10 maxIdle=2 maxWait=1
 logAbandoned=true
username=root password=11
 driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/test/
 /Context

 webroot/web-inf/web.xml:

  resource-ref
   descriptionDB Connection/description
   res-ref-namejdbc/mysql/res-ref-name
   res-typejavax.sql.DataSource/res-type
   res-authContainer/res-auth
 /resource-ref

 webroot/meta-inf/persistence.xml:

 ?xml version=1.0 encoding=UTF-8 standalone=yes?
 persistence
 version=1.0
 xsi:schemaLocation=
 http://java.sun.com/xml/ns/persistence
  http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd
  http://java.sun.com/xml/ns/persistence/orm
  http://java.sun.com/xml/ns/persistence/orm_1_0.xsd;
 xmlns:orm=http://java.sun.com/xml/ns/persistence/orm;
 xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
 xmlns=http://java.sun.com/xml/ns/persistence;

  !--persistence-unit name=ProcessService
   jta-data-sourcejava:/DefaultDS/jta-data-source
   properties
property name=hibernate.hbm2ddl.auto value=create-drop/
   /properties
  /persistence-unit--


 persistence-unit name=org.drools.persistence.jpa
 transaction-type=JTA
 providerorg.hibernate.ejb.HibernatePersistence/provider
 jta-data-sourcejava:comp/env/jdbc/mysql/jta-data-source

 classorg.drools.persistence.session.SessionInfo/class
  classorg.drools.persistence.processinstance.ProcessInstanceInfo/class

 classorg.drools.persistence.processinstance.ProcessInstanceEventInfo/class
 classorg.drools.persistence.processinstance.WorkItemInfo/class


 properties
 property name=hibernate.dialect
 value=org.hibernate.dialect.MySQLDialect/
 property name=hibernate.max_fetch_depth value=3/
 property name=hibernate.hbm2ddl.auto value=create /
 property name=hibernate.show_sql value=true /
 property name=hibernate.transaction.manager_lookup_class
 value=org.hibernate.transaction.BTMTransactionManagerLookup /
 /properties
 /persistence-unit

 /persistence

 webroot/testJNDI.jsp:

 %@ page import='java.sql.*, javax.sql.*, javax.naming.*' %
 %
 Context ic = new InitialContext();
 DataSource ds = (DataSource) ic.lookup(java:comp/env/jdbc/mysql);

 Connection conn = ds.getConnection();

 try {
   Statement stmt = conn.createStatement();
   ResultSet rs = stmt.executeQuery(select * from test);
   while (rs.next()) { %
 %= rs.getString(1) % %= rs.getString(2) %br%
   }
 } finally {
   conn.close();
 }
 %

 webroot/testDroolsFlow.jsp:

 %@ page import='java.sql.*, javax.sql.*, javax.naming.*,com.abc.*' %
 %
 VdcService.exec();
 %

 run the testJNDI.jsp,its OK.when i run testDroolsFlow.jsp, appears this
 exception:

 java.lang.RuntimeException: Could not commit session
 at
 org.drools.persistence.session.SingleSessionCommandService.init(SingleSessionCommandService.java:119)
 at
 org.drools.persistence.jpa.impl.JPAKnowledgeServiceProviderImpl.newStatefulKnowledgeSession(JPAKnowledgeServiceProviderImpl.java:44)
 at
 org.drools.persistence.jpa.JPAKnowledgeService.newStatefulKnowledgeSession(JPAKnowledgeService.java:93)
 at com.abc.VdcService.exec(VdcService.java:39)
 at
 org.apache.jsp._testDroolsFlow_jsp._jspService(_testDroolsFlow_jsp.java:60)
 at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 at
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
 at
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
 at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 at
 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 at
 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at
 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
 at
 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
 at
 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
 at
 

Re: [rules-users] Persistence.createEntityManagerFactory NullPointerException

2010-09-03 Thread Pablo Nussembaum
You need to configure bitronix[0] to provide JTA. Or use drools-spring
that allows you to use drools-persisntece-jpa without JTA.

[0] http://docs.codehaus.org/display/BTM/Tomcat13
On 09/03/2010 08:53 AM, liang wrote:
 i found that tomcat 6 have not JTA,which server is able to persistence?

 在 2010年9月3日 下午12:02,liang zhuyx...@gmail.com
 mailto:zhuyx...@gmail.com写道:

 THS,Esteban,I found it which is resin's problem, so i replaced it
 to tomcat6, i got other questions:

 in my webapp webroot/meta-inf/content.xml:
 ?xml version=1.0 encoding=UTF-8?
 Context
 Resource name=jdbc/mysql auth=Container
 type=javax.sql.DataSource
 maxActive=10 maxIdle=2 maxWait=1 logAbandoned=true
 username=root password=11
 driverClassName=com.mysql.jdbc.Driver
 url=jdbc:mysql://localhost:3306/test/
 /Context

 webroot/web-inf/web.xml:

 resource-ref
 descriptionDB Connection/description
 res-ref-namejdbc/mysql/res-ref-name
 res-typejavax.sql.DataSource/res-type
 res-authContainer/res-auth
 /resource-ref

 webroot/meta-inf/persistence.xml:

 ?xml version=1.0 encoding=UTF-8 standalone=yes?
 persistence
 version=1.0
 xsi:schemaLocation=
 http://java.sun.com/xml/ns/persistence
 http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd
 http://java.sun.com/xml/ns/persistence/orm
 http://java.sun.com/xml/ns/persistence/orm_1_0.xsd;
 xmlns:orm=http://java.sun.com/xml/ns/persistence/orm;
 xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
 xmlns=http://java.sun.com/xml/ns/persistence;

 !--persistence-unit name=ProcessService
 jta-data-sourcejava:/DefaultDS/jta-data-source
 properties
 property name=hibernate.hbm2ddl.auto value=create-drop/
 /properties
 /persistence-unit--


 persistence-unit name=org.drools.persistence.jpa
 transaction-type=JTA
 providerorg.hibernate.ejb.HibernatePersistence/provider
 jta-data-sourcejava:comp/env/jdbc/mysql/jta-data-source
 classorg.drools.persistence.session.SessionInfo/class
 classorg.drools.persistence.processinstance.ProcessInstanceInfo/class
 
 classorg.drools.persistence.processinstance.ProcessInstanceEventInfo/class
 classorg.drools.persistence.processinstance.WorkItemInfo/class


 properties
 property name=hibernate.dialect
 value=org.hibernate.dialect.MySQLDialect/
 property name=hibernate.max_fetch_depth value=3/
 property name=hibernate.hbm2ddl.auto value=create /
 property name=hibernate.show_sql value=true /
 property name=hibernate.transaction.manager_lookup_class
 value=org.hibernate.transaction.BTMTransactionManagerLookup /
 /properties
 /persistence-unit

 /persistence

 webroot/testJNDI.jsp:

 %@ page import='java.sql.*, javax.sql.*, javax.naming.*' %
 %
 Context ic = new InitialContext();
 DataSource ds = (DataSource) ic.lookup(java:comp/env/jdbc/mysql);

 Connection conn = ds.getConnection();

 try {
 Statement stmt = conn.createStatement();
 ResultSet rs = stmt.executeQuery(select * from test);
 while (rs.next()) { %
 %= rs.getString(1) % %= rs.getString(2) %br%
 }
 } finally {
 conn.close();
 }
 %

 webroot/testDroolsFlow.jsp:

 %@ page import='java.sql.*, javax.sql.*, javax.naming.*,com.abc.*' %
 %
 VdcService.exec();
 %

 run the testJNDI.jsp,its OK.when i run testDroolsFlow.jsp, appears
 this exception:

 java.lang.RuntimeException: Could not commit session
 at
 
 org.drools.persistence.session.SingleSessionCommandService.init(SingleSessionCommandService.java:119)
 at
 
 org.drools.persistence.jpa.impl.JPAKnowledgeServiceProviderImpl.newStatefulKnowledgeSession(JPAKnowledgeServiceProviderImpl.java:44)
 at
 
 org.drools.persistence.jpa.JPAKnowledgeService.newStatefulKnowledgeSession(JPAKnowledgeService.java:93)
 at com.abc.VdcService.exec(VdcService.java:39)
 at
 
 org.apache.jsp._testDroolsFlow_jsp._jspService(_testDroolsFlow_jsp.java:60)
 at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 at
 
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
 at
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
 at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 at
 
 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 at
 
 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at
 
 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
 at
 
 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
 at
 

Re: [rules-users] Persistence.createEntityManagerFactory NullPointerException

2010-09-03 Thread Gustavo Tenrreiro
If it helps at all; I spent almost a full week trying to get JPA  to
work with Tomcat 5.5 + Hibernate + Bitronix and this is what I found.

The instructions for Bitronix in
http://docs.codehaus.org/display/BTM/Tomcat13 did not help me much.
The datasource that gets created via the resource.properties could
never be found.

- So to get it to work, do deploy the Bitronix jar files into your
server / context

- In the Tomcat conf/context.xml I do have Transaction
factory=bitronix.tm.BitronixUserTransactionObjectFactory / but I
am not sure if it is required ( haven't tested removing it ).

- In the web.xml I do have:

  resource-env-ref

resource-env-ref-namejava:comp/env/jdbc/processInstanceDS/resource-env-ref-name
resource-env-ref-typejavax.sql.DataSource/resource-env-ref-type
  /resource-env-ref

where jdbc/processInstanceDS is your jdbc/mysql

- In the Hibernate persistence.xml I do have:

  property name=hibernate.transaction.manager_lookup_class
value=org.hibernate.transaction.BTMTransactionManagerLookup /
  property name=hibernate.jndi.class
value=bitronix.tm.jndi.BitronixInitialContextFactory /

although I don't think it is using the jndi.class specified there, so
the second line might be redundant.

Then in my code I create the datasource by hand ( in a ServletContextListener ):

PoolingDataSource ds = new PoolingDataSource();
ds.setUniqueName( jdbc/processInstanceDS );
ds.setClassName( 
bitronix.tm.resource.jdbc.lrc.LrcXADataSource);
ds.setMaxPoolSize( 3 );
ds.setAllowLocalTransactions( true );

ds.getDriverProperties().put(driverClassName,com.microsoft.sqlserver.jdbc.SQLServerDriver);
ds.getDriverProperties().put( user, xxx );
ds.getDriverProperties().put( password,  );
ds.getDriverProperties().put( url, 
mySqlServerUrl... );

replace the driverClassName, user, password, and url for your setup. I
am using SQLServer, but I guess you are on MySql.

After that the JPA stuff works, and persistence works as advertised.
This is the only setup that worked for me. I tried creating the
datasource from Spring but that didn't work either.

Please let me know what you find out.

Thanks


2010/9/3 Pablo Nussembaum bau...@gmail.com:
 You need to configure bitronix[0] to provide JTA. Or use drools-spring that
 allows you to use drools-persisntece-jpa without JTA.

 [0] http://docs.codehaus.org/display/BTM/Tomcat13
 On 09/03/2010 08:53 AM, liang wrote:

 i found that tomcat 6 have not JTA,which server is able to persistence?

 在 2010年9月3日 下午12:02,liang zhuyx...@gmail.com写道:

 THS,Esteban,I found it which is resin's problem, so i replaced it to
 tomcat6, i got other questions:

  in my webapp webroot/meta-inf/content.xml:
 ?xml version=1.0 encoding=UTF-8?
 Context
   Resource name=jdbc/mysql auth=Container type=javax.sql.DataSource
maxActive=10 maxIdle=2 maxWait=1
 logAbandoned=true
username=root password=11
 driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/test/
 /Context

 webroot/web-inf/web.xml:

  resource-ref
   descriptionDB Connection/description
   res-ref-namejdbc/mysql/res-ref-name
   res-typejavax.sql.DataSource/res-type
   res-authContainer/res-auth
 /resource-ref

 webroot/meta-inf/persistence.xml:

 ?xml version=1.0 encoding=UTF-8 standalone=yes?
 persistence
 version=1.0
 xsi:schemaLocation=
 http://java.sun.com/xml/ns/persistence
  http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd
  http://java.sun.com/xml/ns/persistence/orm
  http://java.sun.com/xml/ns/persistence/orm_1_0.xsd;
 xmlns:orm=http://java.sun.com/xml/ns/persistence/orm;
 xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
 xmlns=http://java.sun.com/xml/ns/persistence;

  !--persistence-unit name=ProcessService
   jta-data-sourcejava:/DefaultDS/jta-data-source
   properties
property name=hibernate.hbm2ddl.auto value=create-drop/
   /properties
  /persistence-unit--

 persistence-unit name=org.drools.persistence.jpa
 transaction-type=JTA
 providerorg.hibernate.ejb.HibernatePersistence/provider
 jta-data-sourcejava:comp/env/jdbc/mysql/jta-data-source
 classorg.drools.persistence.session.SessionInfo/class
  classorg.drools.persistence.processinstance.ProcessInstanceInfo/class

 classorg.drools.persistence.processinstance.ProcessInstanceEventInfo/class
 classorg.drools.persistence.processinstance.WorkItemInfo/class


 properties
 property name=hibernate.dialect
 value=org.hibernate.dialect.MySQLDialect/
 property name=hibernate.max_fetch_depth value=3/
 property name=hibernate.hbm2ddl.auto value=create /
 property name=hibernate.show_sql value=true /
  

Re: [rules-users] Persistence.createEntityManagerFactory NullPointerException

2010-09-02 Thread liang
THS,Esteban,I found it which is resin's problem, so i replaced it to
tomcat6, i got other questions:

 in my webapp webroot/meta-inf/content.xml:
?xml version=1.0 encoding=UTF-8?
Context
  Resource name=jdbc/mysql auth=Container type=javax.sql.DataSource
   maxActive=10 maxIdle=2 maxWait=1
logAbandoned=true
   username=root password=11
driverClassName=com.mysql.jdbc.Driver
   url=jdbc:mysql://localhost:3306/test/
/Context

webroot/web-inf/web.xml:

 resource-ref
  descriptionDB Connection/description
  res-ref-namejdbc/mysql/res-ref-name
  res-typejavax.sql.DataSource/res-type
  res-authContainer/res-auth
/resource-ref

webroot/meta-inf/persistence.xml:

?xml version=1.0 encoding=UTF-8 standalone=yes?
persistence
version=1.0
xsi:schemaLocation=
http://java.sun.com/xml/ns/persistence
 http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd
 http://java.sun.com/xml/ns/persistence/orm
 http://java.sun.com/xml/ns/persistence/orm_1_0.xsd;
xmlns:orm=http://java.sun.com/xml/ns/persistence/orm;
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
xmlns=http://java.sun.com/xml/ns/persistence;

 !--persistence-unit name=ProcessService
  jta-data-sourcejava:/DefaultDS/jta-data-source
  properties
   property name=hibernate.hbm2ddl.auto value=create-drop/
  /properties
 /persistence-unit--

persistence-unit name=org.drools.persistence.jpa
transaction-type=JTA
providerorg.hibernate.ejb.HibernatePersistence/provider
jta-data-sourcejava:comp/env/jdbc/mysql/jta-data-source
classorg.drools.persistence.session.SessionInfo/class
 classorg.drools.persistence.processinstance.ProcessInstanceInfo/class

classorg.drools.persistence.processinstance.ProcessInstanceEventInfo/class
classorg.drools.persistence.processinstance.WorkItemInfo/class


properties
property name=hibernate.dialect
value=org.hibernate.dialect.MySQLDialect/
property name=hibernate.max_fetch_depth value=3/
property name=hibernate.hbm2ddl.auto value=create /
property name=hibernate.show_sql value=true /
property name=hibernate.transaction.manager_lookup_class
value=org.hibernate.transaction.BTMTransactionManagerLookup /
/properties
/persistence-unit

/persistence

webroot/testJNDI.jsp:

%@ page import='java.sql.*, javax.sql.*, javax.naming.*' %
%
Context ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup(java:comp/env/jdbc/mysql);

Connection conn = ds.getConnection();

try {
  Statement stmt = conn.createStatement();
  ResultSet rs = stmt.executeQuery(select * from test);
  while (rs.next()) { %
%= rs.getString(1) % %= rs.getString(2) %br%
  }
} finally {
  conn.close();
}
%

webroot/testDroolsFlow.jsp:

%@ page import='java.sql.*, javax.sql.*, javax.naming.*,com.abc.*' %
%
VdcService.exec();
%

run the testJNDI.jsp,its OK.when i run testDroolsFlow.jsp, appears this
exception:

java.lang.RuntimeException: Could not commit session
at
org.drools.persistence.session.SingleSessionCommandService.init(SingleSessionCommandService.java:119)
at
org.drools.persistence.jpa.impl.JPAKnowledgeServiceProviderImpl.newStatefulKnowledgeSession(JPAKnowledgeServiceProviderImpl.java:44)
at
org.drools.persistence.jpa.JPAKnowledgeService.newStatefulKnowledgeSession(JPAKnowledgeService.java:93)
at com.abc.VdcService.exec(VdcService.java:39)
at
org.apache.jsp._testDroolsFlow_jsp._jspService(_testDroolsFlow_jsp.java:60)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
at
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at

[rules-users] Persistence.createEntityManagerFactory NullPointerException

2010-09-01 Thread 亮亮
hi:

in my webapp, I use JPA to store the runtime state,i use this code in
VdcService.java which is a sample  java class:

EntityManagerFactory emf =Persistence.createEntityManagerFactory(
org.drools.persistence.jpa );
Environment env = KnowledgeBaseFactory.newEnvironment();
env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );

 // create a new knowledge session that uses JPA to store the runtime state
StatefulKnowledgeSession ksession =
JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );

I put persistence.xml to webRoot/META-INF/  , persistence.xml:

?xml version=1.0 encoding=UTF-8 standalone=yes?
persistence
version=1.0
xsi:schemaLocation=
http://java.sun.com/xml/ns/persistence
 http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd
 http://java.sun.com/xml/ns/persistence/orm
 http://java.sun.com/xml/ns/persistence/orm_1_0.xsd;
xmlns:orm=http://java.sun.com/xml/ns/persistence/orm;
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
xmlns=http://java.sun.com/xml/ns/persistence;

persistence-unit name=org.drools.persistence.jpa
transaction-type=JTA
providerorg.hibernate.ejb.HibernatePersistence/provider
jta-data-sourcejava:comp/env/jdbc/mysql/jta-data-source
classorg.drools.persistence.session.SessionInfo/class
 classorg.drools.persistence.processinstance.ProcessInstanceInfo/class

classorg.drools.persistence.processinstance.ProcessInstanceEventInfo/class
classorg.drools.persistence.processinstance.WorkItemInfo/class


properties
property name=hibernate.dialect
value=org.hibernate.dialect.MySQLDialect/
property name=hibernate.max_fetch_depth value=3/
property name=hibernate.hbm2ddl.auto value=create /
property name=hibernate.show_sql value=true /
property name=hibernate.transaction.manager_lookup_class
value=org.hibernate.transaction.BTMTransactionManagerLookup /
/properties
/persistence-unit

/persistence

I use resin 3.1.10,  $resin-home/conf/resin.conf:

   database
   jndi-namejdbc/mysql/jndi-name
   driver type=org.gjt.mm.mysql.Driver
 urljdbc:mysql://127.0.0.1:3306/test/url
 userroot/user
 password/password
/driver
prepared-statement-cache-size8/prepared-statement-cache-size
max-connections20/max-connections
max-idle-time30s/max-idle-time
  /database

when i run this webapp , i got this exception:

java.lang.NullPointerException
at
com.caucho.amber.manager.AmberPersistenceProvider.createEntityManagerFactory(AmberPersistenceProvider.java:65)
at
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)
at com.abc.abc.service.VdcService.exec(VdcService.java:32)
at com.abc.abc.resources.Apply.apply(Apply.java:55)
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:597)
at
com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:156)
at
com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:67)
at
com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:208)
at
com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:75)
at
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:115)
at
com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:67)
at
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:724)
at
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:689)
at
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:680)
at
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:324)
at
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:425)
at
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:604)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:91)
at
com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:103)
at
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:416)
at
com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:87)
at
org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:99)
at

Re: [rules-users] Persistence.createEntityManagerFactory NullPointerException

2010-09-01 Thread Esteban Aliverti
As far as I can see, this has nothing to do with drools. You can't even
create the EntityManagerFactory. Try to set a finest log level for
com.caucho.amber.*
and org.hibernate.* to see why it is throwing a NPE.

Best,



Esteban Aliverti
- Developer @ http://www.plugtree.com
- Blog @ http://ilesteban.wordpress.com


2010/9/1 亮亮 zhuyx...@gmail.com

 hi:

 in my webapp, I use JPA to store the runtime state,i use this code in
 VdcService.java which is a sample  java class:

 EntityManagerFactory emf =Persistence.createEntityManagerFactory(
 org.drools.persistence.jpa );
 Environment env = KnowledgeBaseFactory.newEnvironment();
 env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );

  // create a new knowledge session that uses JPA to store the runtime state
 StatefulKnowledgeSession ksession =
 JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );

 I put persistence.xml to webRoot/META-INF/  , persistence.xml:

 ?xml version=1.0 encoding=UTF-8 standalone=yes?
 persistence
 version=1.0
 xsi:schemaLocation=
 http://java.sun.com/xml/ns/persistence
  http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd
  http://java.sun.com/xml/ns/persistence/orm
  http://java.sun.com/xml/ns/persistence/orm_1_0.xsd;
 xmlns:orm=http://java.sun.com/xml/ns/persistence/orm;
 xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
 xmlns=http://java.sun.com/xml/ns/persistence;

 persistence-unit name=org.drools.persistence.jpa
 transaction-type=JTA
 providerorg.hibernate.ejb.HibernatePersistence/provider
 jta-data-sourcejava:comp/env/jdbc/mysql/jta-data-source
 classorg.drools.persistence.session.SessionInfo/class
  classorg.drools.persistence.processinstance.ProcessInstanceInfo/class

 classorg.drools.persistence.processinstance.ProcessInstanceEventInfo/class
 classorg.drools.persistence.processinstance.WorkItemInfo/class


 properties
 property name=hibernate.dialect
 value=org.hibernate.dialect.MySQLDialect/
 property name=hibernate.max_fetch_depth value=3/
 property name=hibernate.hbm2ddl.auto value=create /
 property name=hibernate.show_sql value=true /
 property name=hibernate.transaction.manager_lookup_class
 value=org.hibernate.transaction.BTMTransactionManagerLookup /
 /properties
 /persistence-unit

 /persistence

 I use resin 3.1.10,  $resin-home/conf/resin.conf:

database
jndi-namejdbc/mysql/jndi-name
driver type=org.gjt.mm.mysql.Driver
  urljdbc:mysql://127.0.0.1:3306/test/url
  userroot/user
  password/password
 /driver

 prepared-statement-cache-size8/prepared-statement-cache-size
 max-connections20/max-connections
 max-idle-time30s/max-idle-time
   /database

 when i run this webapp , i got this exception:

 java.lang.NullPointerException
 at
 com.caucho.amber.manager.AmberPersistenceProvider.createEntityManagerFactory(AmberPersistenceProvider.java:65)
 at
 javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)
 at com.abc.abc.service.VdcService.exec(VdcService.java:32)
 at com.abc.abc.resources.Apply.apply(Apply.java:55)
 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:597)
 at
 com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:156)
 at
 com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:67)
 at
 com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:208)
 at
 com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:75)
 at
 com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:115)
 at
 com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:67)
 at
 com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:724)
 at
 com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:689)
 at
 com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:680)
 at
 com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:324)
 at
 com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:425)
 at
 com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:604)
 at