You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by JensToerber <je...@juwimm.com> on 2008/11/02 22:30:20 UTC

OpenEJB on Oracle

Hi altogether,

i am using OpenEJB 3.x as standalone edition for JUnit tests and i tried to
get OpenEJB Examples running on Tomcat 6.0.x. on Oracle 10g.

I have problems configuring the persistence units and/or datasources. I am
not quite sure what the problem is:

persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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">
	<!--
	only one persistence unit per project by JPA Tools supported
	-->
	<!--
	<persistence-unit name="JPATestProject">
	</persistence-unit>
	-->
	<persistence-unit name="beds_pu" transaction-type="JTA">
		<provider>org.hibernate.ejb.HibernatePersistence</provider>
		<jta-data-source>OracleORCL</jta-data-source>
		<non-jta-data-source>OracleORCLUnmanaged</non-jta-data-source> 
        <class>info.toerber.beds.model.Test</class>
	</persistence-unit>
</persistence>

in one of my session beans i am declaring a datasource like:
@Resource(name="OracleORCL")
    DataSource dataSource;

In standalone for JUnit-Test it seems to be that OpenEJB always takes its
default Database HSQL.
Is this correct?
Is it possible to change this to an Oracle Datasource?

here is my openejb.xml in META-INF for standalone and in <tomcat>/conf for
Tomcat deployment:
<openejb>
	<Resource id="OracleORCL" type="DataSource">
    #  Oracle example
    #
    #  This connector will not work until you download the driver at:
    #  http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html
    JdbcDriver  oracle.jdbc.OracleDriver
    JdbcUrl     jdbc:oracle:thin:@192.168.2.96:1521:ORCL
    UserName    openejb
    Password    openejb
	JtaManaged true
</Resource>
<Resource id="OracleORCLUnmanaged" type="DataSource">
    #  Oracle example
    #
    #  This connector will not work until you download the driver at:
    #  http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html
    JdbcDriver  oracle.jdbc.OracleDriver
    JdbcUrl     jdbc:oracle:thin:@192.168.2.96:1521:ORCL
    UserName    openejb
    Password    openejb
	JtaManaged  false
</Resource>
</openejb>

The examples are running in Tomcat, but always on HSQL as i can see with

if (this.entityManager != null) {
				Object delegate = this.entityManager.getDelegate();
				if (delegate instanceof HibernateEntityManager) {
						HibernateEntityManager hibernateEntityManager =
(HibernateEntityManager) delegate;
						Session s = hibernateEntityManager.getSession();
						Connection conn = s.connection();
						inspectConnection(conn);

private void inspectConnection(Connection conn) throws SQLException {
		DatabaseMetaData dataBaseMetaData = conn.getMetaData();
		// The drivers are included with OpenEJB 3.0 and HSQLDB is the default
database.
		System.out.println(dataBaseMetaData.getDatabaseMajorVersion());
		System.out.println(dataBaseMetaData.getDatabaseMinorVersion());
		System.out.println(dataBaseMetaData.getDatabaseProductName());
		System.out.println(dataBaseMetaData.getDatabaseProductVersion());
		System.out.println(dataBaseMetaData.getDefaultTransactionIsolation());
		System.out.println(dataBaseMetaData.getDriverMajorVersion());
		System.out.println(dataBaseMetaData.getDriverMinorVersion());
		System.out.println(dataBaseMetaData.getDriverName());
		System.out.println(dataBaseMetaData.getDriverVersion());

I could change the default Persistence Provider, but it's not running on my
Oracle Datasource.
Looked in the documentation and i can see that HSQL is the default database.
But how and where can i change it always or for a specific persistence unit
or for a resource in standalone and/or Tomcat?

Btw. the persistence unit works if i take this in Eclipse JPA Tools:
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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">
	<!--
	only one persistence unit per project by JPA Tools supported
	-->
	<!--
	<persistence-unit name="JPATestProject">
	</persistence-unit>
	-->
	<persistence-unit name="beds_pu" transaction-type="RESOURCE_LOCAL">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <!-- use persistence.xml right mouse Synchronize classes to get actual
list -->
      <class>info.toerber.beds.model.Test</class>
      <properties>
         <property name="hibernate.dialect"
value="org.hibernate.dialect.Oracle10gDialect"/>
         <property name="hibernate.connection.driver_class"
value="oracle.jdbc.OracleDriver"/>
         <property name="hibernate.connection.username" value="openejb"/>
         <property name="hibernate.connection.password" value="openejb"/>
         <property name="hibernate.connection.url"
value="jdbc:oracle:thin:@192.168.2.96:1521:ORCL"/>
         <property name="hibernate.max_fetch_depth" value="3"/>
         <!-- JPA Tools looks for this setting(?), so does not always drop
the table as announced -->
         <property name="hibernate.hbm2ddl.auto" value="update" />
       	 <!--
         creates table at start and drops at the end!!
         <property name="hibernate.hbm2ddl.auto" value="create-drop" />
       	 -->
         <!-- cache configuration
         <property
name="hibernate.ejb.classcache.org.hibernate.ejb.test.Item"
value="read-write"/>
         <property
name="hibernate.ejb.collectioncache.org.hibernate.ejb.test.Item.distributors"
value="read-write, RegionName"/>
         -->

         <!-- alternatively to <class> and <property> declarations, you can
use a regular hibernate.cfg.xml file -->
         <!-- property name="hibernate.ejb.cfgfile"
value="/org/hibernate/ejb/test/hibernate.cfg.xml"/ -->
      </properties>
   </persistence-unit>
</persistence>

Any help welcome.
Thanks in advance.

Jens Toerber
-- 
View this message in context: http://www.nabble.com/OpenEJB-on-Oracle-tp20294024p20294024.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: OpenEJB on Oracle

Posted by David Blevins <da...@visi.com>.
The first persistence.xml file looks accurate as does the  
openejb.xml.  I wonder if the openejb.xml is getting picked up.  If  
one isn't found we auto create one in tomcat.base/conf/openejb.xml.

If you can post your openejb log output that should give us some  
indication of what's going on.

-David


On Nov 2, 2008, at 1:30 PM, JensToerber wrote:

>
> Hi altogether,
>
> i am using OpenEJB 3.x as standalone edition for JUnit tests and i  
> tried to
> get OpenEJB Examples running on Tomcat 6.0.x. on Oracle 10g.
>
> I have problems configuring the persistence units and/or  
> datasources. I am
> not quite sure what the problem is:
>
> persistence.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> <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">
> 	<!--
> 	only one persistence unit per project by JPA Tools supported
> 	-->
> 	<!--
> 	<persistence-unit name="JPATestProject">
> 	</persistence-unit>
> 	-->
> 	<persistence-unit name="beds_pu" transaction-type="JTA">
> 		<provider>org.hibernate.ejb.HibernatePersistence</provider>
> 		<jta-data-source>OracleORCL</jta-data-source>
> 		<non-jta-data-source>OracleORCLUnmanaged</non-jta-data-source>
>        <class>info.toerber.beds.model.Test</class>
> 	</persistence-unit>
> </persistence>
>
> in one of my session beans i am declaring a datasource like:
> @Resource(name="OracleORCL")
>    DataSource dataSource;
>
> In standalone for JUnit-Test it seems to be that OpenEJB always  
> takes its
> default Database HSQL.
> Is this correct?
> Is it possible to change this to an Oracle Datasource?
>
> here is my openejb.xml in META-INF for standalone and in <tomcat>/ 
> conf for
> Tomcat deployment:
> <openejb>
> 	<Resource id="OracleORCL" type="DataSource">
>    #  Oracle example
>    #
>    #  This connector will not work until you download the driver at:
>    #  http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html
>    JdbcDriver  oracle.jdbc.OracleDriver
>    JdbcUrl     jdbc:oracle:thin:@192.168.2.96:1521:ORCL
>    UserName    openejb
>    Password    openejb
> 	JtaManaged true
> </Resource>
> <Resource id="OracleORCLUnmanaged" type="DataSource">
>    #  Oracle example
>    #
>    #  This connector will not work until you download the driver at:
>    #  http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html
>    JdbcDriver  oracle.jdbc.OracleDriver
>    JdbcUrl     jdbc:oracle:thin:@192.168.2.96:1521:ORCL
>    UserName    openejb
>    Password    openejb
> 	JtaManaged  false
> </Resource>
> </openejb>
>
> The examples are running in Tomcat, but always on HSQL as i can see  
> with
>
> if (this.entityManager != null) {
> 				Object delegate = this.entityManager.getDelegate();
> 				if (delegate instanceof HibernateEntityManager) {
> 						HibernateEntityManager hibernateEntityManager =
> (HibernateEntityManager) delegate;
> 						Session s = hibernateEntityManager.getSession();
> 						Connection conn = s.connection();
> 						inspectConnection(conn);
>
> private void inspectConnection(Connection conn) throws SQLException {
> 		DatabaseMetaData dataBaseMetaData = conn.getMetaData();
> 		// The drivers are included with OpenEJB 3.0 and HSQLDB is the  
> default
> database.
> 		System.out.println(dataBaseMetaData.getDatabaseMajorVersion());
> 		System.out.println(dataBaseMetaData.getDatabaseMinorVersion());
> 		System.out.println(dataBaseMetaData.getDatabaseProductName());
> 		System.out.println(dataBaseMetaData.getDatabaseProductVersion());
> 		 
> System.out.println(dataBaseMetaData.getDefaultTransactionIsolation());
> 		System.out.println(dataBaseMetaData.getDriverMajorVersion());
> 		System.out.println(dataBaseMetaData.getDriverMinorVersion());
> 		System.out.println(dataBaseMetaData.getDriverName());
> 		System.out.println(dataBaseMetaData.getDriverVersion());
>
> I could change the default Persistence Provider, but it's not  
> running on my
> Oracle Datasource.
> Looked in the documentation and i can see that HSQL is the default  
> database.
> But how and where can i change it always or for a specific  
> persistence unit
> or for a resource in standalone and/or Tomcat?
>
> Btw. the persistence unit works if i take this in Eclipse JPA Tools:
> persistence.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> <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">
> 	<!--
> 	only one persistence unit per project by JPA Tools supported
> 	-->
> 	<!--
> 	<persistence-unit name="JPATestProject">
> 	</persistence-unit>
> 	-->
> 	<persistence-unit name="beds_pu" transaction-type="RESOURCE_LOCAL">
>      <provider>org.hibernate.ejb.HibernatePersistence</provider>
>      <!-- use persistence.xml right mouse Synchronize classes to get  
> actual
> list -->
>      <class>info.toerber.beds.model.Test</class>
>      <properties>
>         <property name="hibernate.dialect"
> value="org.hibernate.dialect.Oracle10gDialect"/>
>         <property name="hibernate.connection.driver_class"
> value="oracle.jdbc.OracleDriver"/>
>         <property name="hibernate.connection.username"  
> value="openejb"/>
>         <property name="hibernate.connection.password"  
> value="openejb"/>
>         <property name="hibernate.connection.url"
> value="jdbc:oracle:thin:@192.168.2.96:1521:ORCL"/>
>         <property name="hibernate.max_fetch_depth" value="3"/>
>         <!-- JPA Tools looks for this setting(?), so does not always  
> drop
> the table as announced -->
>         <property name="hibernate.hbm2ddl.auto" value="update" />
>       	 <!--
>         creates table at start and drops at the end!!
>         <property name="hibernate.hbm2ddl.auto" value="create-drop" />
>       	 -->
>         <!-- cache configuration
>         <property
> name="hibernate.ejb.classcache.org.hibernate.ejb.test.Item"
> value="read-write"/>
>         <property
> name 
> = 
> "hibernate 
> .ejb.collectioncache.org.hibernate.ejb.test.Item.distributors"
> value="read-write, RegionName"/>
>         -->
>
>         <!-- alternatively to <class> and <property> declarations,  
> you can
> use a regular hibernate.cfg.xml file -->
>         <!-- property name="hibernate.ejb.cfgfile"
> value="/org/hibernate/ejb/test/hibernate.cfg.xml"/ -->
>      </properties>
>   </persistence-unit>
> </persistence>
>
> Any help welcome.
> Thanks in advance.
>
> Jens Toerber
> -- 
> View this message in context: http://www.nabble.com/OpenEJB-on-Oracle-tp20294024p20294024.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
>


Re: OpenEJB on Oracle

Posted by JensToerber <je...@juwimm.com>.
Hi David,

thanks a lot for your support:

I)
i tried the javax.mail.Session Resource:

What i found out:
a) If you specify the pass-through Properties in 
<Resource id="BedsMailSession" type="javax.mail.Session">
	# mail.host=""
	mail.pop3.user=jens.toerber
	mail.pop3.host=pop.web.de
	mail.pop3.port=110
	mail.smtp.host=smtp.web.de
	mail.smtp.port=25
	mail.transport.protocol=smtp
	mail.smtp.auth="true" 
	mail.smtp.user="jens.toerber" 
	password="thrillie" 
</Resource>

you get a WARN-Level log-entry that those Properties are not supported. I
guess INFO-Level with a hint that they are passed through would be better.
b) You have to be very careful with the properties:
# "25" not allowed, not even 25<blank>, but
	mail.smtp.port=25
# "smtp" not allowed, not even smtp<blank>!!
	mail.transport.protocol=smtp
# "smtp.web.de" not allowed, but
	mail.smtp.host=smtp.web.de

, hence you have to be very careful and the values you specified do not
work. I could not test everything, because there are different types of
smtp-servers (pop3 before smtp, smtp authentification, ...). I guess also 

mail.smtp.user="jens.toerber"

is not correct, but

mail.smtp.user=jens.toerber


, but i cannot prove it.

But if you take care, Mail-Sessions are working. Would be great to really
document this very precise.

II)
New-Connection-sql:
JBoss has in it's datasource the new-connection-sql element and Weblogic 8.1
has an InitSQL on it's connection pool. Hence i could say, they support this
feature, and so should Openejb, but to be more specific:
a) In Oracle you may change NLS_SORT (XGERMAN_DIN) via ALTER SESSION ...
b) You may enable Database SQL trace:
ALTER SESSION SET SQL_TRACE=true (ok, you may do this by
DBMS_SESSION.SET_SQL_TRACE (sql_trace IN BOOLEAN), ... even from a different
session)
c) You may set the Oprimzer Mode for Oracle:
JBoss *-ds.xml:
...
  <new-connection-sql>begin EXECUTE IMMEDIATE 'ALTER SESSION SET
NLS_SORT=''XGERMAN_DIN''';EXECUTE IMMEDIATE 'ALTER SESSION SET
optimizer_mode=''FIRST_ROWS'''; end;</new-connection-sql> 
...

Ok, not very typical. Hence i guess there are a lot of samples for needing a
New-Connection-SQL statement.

There may by EntityManager Interceptors or Listeners in EJB3, but our
Deployers like to control it like that.

Would be great to have this feature in Openejb as well.

III)
Timer
I'll attach my sample:
Simple Timer Bean with a Timeout-Method and an initialization Method, which
is called by a ServletContextListener.

The example is working in JBoss 4.2. In Openejb-JUnit it is also working,
but i suppose it is because in my test i hold a reference to the TimerBean.
That's why i tried to put a reference to the TimerBean in the
ServletContextListener as an attribute in the ServletContext to simulate the
JUnit-Test behaviour.

It gets initialized, but never fires in Tomcat 6.0.18 and Openejb 3.1 in the
Container, but as already said in the JUnit test.

Any help appreciated.

IV) I think CXF is ok delivered with Openejb. Would be nice to hear, if you
try to upgrade the versions i told you, to support Hibernate without any
changes (it's because our old applications are used to it).

Best regards,

Jens


Hi altogether,

i am using OpenEJB 3.x as standalone edition for JUnit tests and i tried to
get OpenEJB Examples running on Tomcat 6.0.x. on Oracle 10g.

I have problems configuring the persistence units and/or datasources. I am
not quite sure what the problem is:

persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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">
	<!--
	only one persistence unit per project by JPA Tools supported
	-->
	<!--
	<persistence-unit name="JPATestProject">
	</persistence-unit>
	-->
	<persistence-unit name="beds_pu" transaction-type="JTA">
		<provider>org.hibernate.ejb.HibernatePersistence</provider>
		<jta-data-source>OracleORCL</jta-data-source>
		<non-jta-data-source>OracleORCLUnmanaged</non-jta-data-source> 
        <class>info.toerber.beds.model.Test</class>
	</persistence-unit>
</persistence>

in one of my session beans i am declaring a datasource like:
@Resource(name="OracleORCL")
    DataSource dataSource;

In standalone for JUnit-Test it seems to be that OpenEJB always takes its
default Database HSQL.
Is this correct?
Is it possible to change this to an Oracle Datasource?

here is my openejb.xml in META-INF for standalone and in <tomcat>/conf for
Tomcat deployment:
<openejb>
	<Resource id="OracleORCL" type="DataSource">
    #  Oracle example
    #
    #  This connector will not work until you download the driver at:
    #  http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html
    JdbcDriver  oracle.jdbc.OracleDriver
    JdbcUrl     jdbc:oracle:thin:@192.168.2.96:1521:ORCL
    UserName    openejb
    Password    openejb
	JtaManaged true
</Resource>
<Resource id="OracleORCLUnmanaged" type="DataSource">
    #  Oracle example
    #
    #  This connector will not work until you download the driver at:
    #  http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html
    JdbcDriver  oracle.jdbc.OracleDriver
    JdbcUrl     jdbc:oracle:thin:@192.168.2.96:1521:ORCL
    UserName    openejb
    Password    openejb
	JtaManaged  false
</Resource>
</openejb>

The examples are running in Tomcat, but always on HSQL as i can see with

if (this.entityManager != null) {
				Object delegate = this.entityManager.getDelegate();
				if (delegate instanceof HibernateEntityManager) {
						HibernateEntityManager hibernateEntityManager =
(HibernateEntityManager) delegate;
						Session s = hibernateEntityManager.getSession();
						Connection conn = s.connection();
						inspectConnection(conn);

private void inspectConnection(Connection conn) throws SQLException {
		DatabaseMetaData dataBaseMetaData = conn.getMetaData();
		// The drivers are included with OpenEJB 3.0 and HSQLDB is the default
database.
		System.out.println(dataBaseMetaData.getDatabaseMajorVersion());
		System.out.println(dataBaseMetaData.getDatabaseMinorVersion());
		System.out.println(dataBaseMetaData.getDatabaseProductName());
		System.out.println(dataBaseMetaData.getDatabaseProductVersion());
		System.out.println(dataBaseMetaData.getDefaultTransactionIsolation());
		System.out.println(dataBaseMetaData.getDriverMajorVersion());
		System.out.println(dataBaseMetaData.getDriverMinorVersion());
		System.out.println(dataBaseMetaData.getDriverName());
		System.out.println(dataBaseMetaData.getDriverVersion());

I could change the default Persistence Provider, but it's not running on my
Oracle Datasource.
Looked in the documentation and i can see that HSQL is the default database.
But how and where can i change it always or for a specific persistence unit
or for a resource in standalone and/or Tomcat?

Btw. the persistence unit works if i take this in Eclipse JPA Tools:
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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">
	<!--
	only one persistence unit per project by JPA Tools supported
	-->
	<!--
	<persistence-unit name="JPATestProject">
	</persistence-unit>
	-->
	<persistence-unit name="beds_pu" transaction-type="RESOURCE_LOCAL">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <!-- use persistence.xml right mouse Synchronize classes to get actual
list -->
      <class>info.toerber.beds.model.Test</class>
      <properties>
         <property name="hibernate.dialect"
value="org.hibernate.dialect.Oracle10gDialect"/>
         <property name="hibernate.connection.driver_class"
value="oracle.jdbc.OracleDriver"/>
         <property name="hibernate.connection.username" value="openejb"/>
         <property name="hibernate.connection.password" value="openejb"/>
         <property name="hibernate.connection.url"
value="jdbc:oracle:thin:@192.168.2.96:1521:ORCL"/>
         <property name="hibernate.max_fetch_depth" value="3"/>
         <!-- JPA Tools looks for this setting(?), so does not always drop
the table as announced -->
         <property name="hibernate.hbm2ddl.auto" value="update" />
       	 <!--
         creates table at start and drops at the end!!
         <property name="hibernate.hbm2ddl.auto" value="create-drop" />
       	 -->
         <!-- cache configuration
         <property
name="hibernate.ejb.classcache.org.hibernate.ejb.test.Item"
value="read-write"/>
         <property
name="hibernate.ejb.collectioncache.org.hibernate.ejb.test.Item.distributors"
value="read-write, RegionName"/>
         -->

         <!-- alternatively to <class> and <property> declarations, you can
use a regular hibernate.cfg.xml file -->
         <!-- property name="hibernate.ejb.cfgfile"
value="/org/hibernate/ejb/test/hibernate.cfg.xml"/ -->
      </properties>
   </persistence-unit>
</persistence>

Any help welcome.
Thanks in advance.

Jens Toerber

http://www.nabble.com/file/p21552837/TimerBean.java TimerBean.java 
http://www.nabble.com/file/p21552837/TimerBeanLocal.java TimerBeanLocal.java 
http://www.nabble.com/file/p21552837/TimerServletContextListener.java
TimerServletContextListener.java 
http://www.nabble.com/file/p21552837/TimerBeanLocalTest.java
TimerBeanLocalTest.java 
-- 
View this message in context: http://www.nabble.com/OpenEJB-on-Oracle-tp20294024p21552837.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: OpenEJB on Oracle

Posted by David Blevins <da...@visi.com>.
On Jan 19, 2009, at 2:20 PM, JensToerber wrote:

>
> Hi David,
>
> thanks a lot for your support:
>
> I)
> i tried the javax.mail.Session Resource:
>
> What i found out:
> a) If you specify the pass-through Properties in
> <Resource id="BedsMailSession" type="javax.mail.Session">
> 	# mail.host=""
> 	mail.pop3.user=jens.toerber
> 	mail.pop3.host=pop.web.de
> 	mail.pop3.port=110
> 	mail.smtp.host=smtp.web.de
> 	mail.smtp.port=25
> 	mail.transport.protocol=smtp
> 	mail.smtp.auth="true"
> 	mail.smtp.user="jens.toerber"
> 	password="thrillie"
> </Resource>
>
> you get a WARN-Level log-entry that those Properties are not  
> supported. I
> guess INFO-Level with a hint that they are passed through would be  
> better.

Right, exactly.  That's an oversight on our part.  We'll need to get  
that code updated not to warn in situations where properties are  
passed directly through.

Logged that so we can track it:  https://issues.apache.org/jira/browse/OPENEJB-989

> b) You have to be very careful with the properties:
> # "25" not allowed, not even 25<blank>, but
> 	mail.smtp.port=25
> # "smtp" not allowed, not even smtp<blank>!!
> 	mail.transport.protocol=smtp
> # "smtp.web.de" not allowed, but
> 	mail.smtp.host=smtp.web.de
>
> , hence you have to be very careful and the values you specified do  
> not
> work. I could not test everything, because there are different types  
> of
> smtp-servers (pop3 before smtp, smtp authentification, ...). I guess  
> also
>
> mail.smtp.user="jens.toerber"
>
> is not correct, but
>
> mail.smtp.user=jens.toerber
>
>
> , but i cannot prove it.

My mistake for showing with quotes, I forgot that java.util.Properties  
will not strip those out.

I was a bit surprised to find that java.util.Properties doesn't strip  
the whitespace off the end of a property value.  I find that strange  
as it will strip the whitespace off the front and end of the property  
name and will strip the whitespace off the front of the property  
value.  Seems inconsistent, but I can understand why they did it that  
way.

In our situation I don't think it's useful.  We do have a more  
powerful subclass of java.util.Properties we use and in that we could  
add an option to trim whitespace off the end of property values as well.

Added a jira for this as well:  https://issues.apache.org/jira/browse/OPENEJB-990

> But if you take care, Mail-Sessions are working. Would be great to  
> really
> document this very precise.

Added this doc with the text from the thread.

http://cwiki.apache.org/OPENEJBx30/configuring-javamail.html

It could likely be more verbose perhaps even show a bean that uses  
javamail.  Contributions are very welcome.  If you're interested in  
helping I can hook you up in our wiki.

> II)
> New-Connection-sql:
> JBoss has in it's datasource the new-connection-sql element and  
> Weblogic 8.1
> has an InitSQL on it's connection pool. Hence i could say, they  
> support this
> feature, and so should Openejb, but to be more specific:
> a) In Oracle you may change NLS_SORT (XGERMAN_DIN) via ALTER  
> SESSION ...
> b) You may enable Database SQL trace:
> ALTER SESSION SET SQL_TRACE=true (ok, you may do this by
> DBMS_SESSION.SET_SQL_TRACE (sql_trace IN BOOLEAN), ... even from a  
> different
> session)
> c) You may set the Oprimzer Mode for Oracle:
> JBoss *-ds.xml:
> ...
>  <new-connection-sql>begin EXECUTE IMMEDIATE 'ALTER SESSION SET
> NLS_SORT=''XGERMAN_DIN''';EXECUTE IMMEDIATE 'ALTER SESSION SET
> optimizer_mode=''FIRST_ROWS'''; end;</new-connection-sql>
> ...
>
> Ok, not very typical. Hence i guess there are a lot of samples for  
> needing a
> New-Connection-SQL statement.
>
> There may by EntityManager Interceptors or Listeners in EJB3, but our
> Deployers like to control it like that.
>
> Would be great to have this feature in Openejb as well.

We're using commons-dbcp for our jdbc connection pooling.  If it has  
such functionality it should be fairly straightforward to wire it in.

> III)
> Timer
> I'll attach my sample:
> Simple Timer Bean with a Timeout-Method and an initialization  
> Method, which
> is called by a ServletContextListener.
>
> The example is working in JBoss 4.2. In Openejb-JUnit it is also  
> working,
> but i suppose it is because in my test i hold a reference to the  
> TimerBean.
> That's why i tried to put a reference to the TimerBean in the
> ServletContextListener as an attribute in the ServletContext to  
> simulate the
> JUnit-Test behaviour.
>
> It gets initialized, but never fires in Tomcat 6.0.18 and Openejb  
> 3.1 in the
> Container, but as already said in the JUnit test.
>
> Any help appreciated.

That might be a little tricky to debug without an app that can  
reproduce the issue.

> IV) I think CXF is ok delivered with Openejb. Would be nice to hear,  
> if you
> try to upgrade the versions i told you, to support Hibernate without  
> any
> changes (it's because our old applications are used to it).

It should be possible to upgrade CXF or remove it entirely provided  
you also remove the openejb-cxf jar.  Likely upgrading the slf4j jars  
without changing the CXF jars would be ok, but I can't say for certain.

-David


Re: OpenEJB on Oracle

Posted by JensToerber <je...@juwimm.com>.
Hi David,

thanks a lot for your support:

I)
i tried the javax.mail.Session Resource:

What i found out:
a) If you specify the pass-through Properties in 
<Resource id="BedsMailSession" type="javax.mail.Session">
	# mail.host=""
	mail.pop3.user=jens.toerber
	mail.pop3.host=pop.web.de
	mail.pop3.port=110
	mail.smtp.host=smtp.web.de
	mail.smtp.port=25
	mail.transport.protocol=smtp
	mail.smtp.auth="true" 
	mail.smtp.user="jens.toerber" 
	password="thrillie" 
</Resource>

you get a WARN-Level log-entry that those Properties are not supported. I
guess INFO-Level with a hint that they are passed through would be better.
b) You have to be very careful with the properties:
# "25" not allowed, not even 25<blank>, but
	mail.smtp.port=25
# "smtp" not allowed, not even smtp<blank>!!
	mail.transport.protocol=smtp
# "smtp.web.de" not allowed, but
	mail.smtp.host=smtp.web.de

, hence you have to be very careful and the values you specified do not
work. I could not test everything, because there are different types of
smtp-servers (pop3 before smtp, smtp authentification, ...). I guess also 

mail.smtp.user="jens.toerber"

is not correct, but

mail.smtp.user=jens.toerber


, but i cannot prove it.

But if you take care, Mail-Sessions are working. Would be great to really
document this very precise.

II)
New-Connection-sql:
JBoss has in it's datasource the new-connection-sql element and Weblogic 8.1
has an InitSQL on it's connection pool. Hence i could say, they support this
feature, and so should Openejb, but to be more specific:
a) In Oracle you may change NLS_SORT (XGERMAN_DIN) via ALTER SESSION ...
b) You may enable Database SQL trace:
ALTER SESSION SET SQL_TRACE=true (ok, you may do this by
DBMS_SESSION.SET_SQL_TRACE (sql_trace IN BOOLEAN), ... even from a different
session)
c) You may set the Oprimzer Mode for Oracle:
JBoss *-ds.xml:
...
  <new-connection-sql>begin EXECUTE IMMEDIATE 'ALTER SESSION SET
NLS_SORT=''XGERMAN_DIN''';EXECUTE IMMEDIATE 'ALTER SESSION SET
optimizer_mode=''FIRST_ROWS'''; end;</new-connection-sql> 
...

Ok, not very typical. Hence i guess there are a lot of samples for needing a
New-Connection-SQL statement.

There may by EntityManager Interceptors or Listeners in EJB3, but our
Deployers like to control it like that.

Would be great to have this feature in Openejb as well.

III)
Timer
I'll attach my sample:
Simple Timer Bean with a Timeout-Method and an initialization Method, which
is called by a ServletContextListener.

The example is working in JBoss 4.2. In Openejb-JUnit it is also working,
but i suppose it is because in my test i hold a reference to the TimerBean.
That's why i tried to put a reference to the TimerBean in the
ServletContextListener as an attribute in the ServletContext to simulate the
JUnit-Test behaviour.

It gets initialized, but never fires in Tomcat 6.0.18 and Openejb 3.1 in the
Container, but as already said in the JUnit test.

Any help appreciated.

IV) I think CXF is ok delivered with Openejb. Would be nice to hear, if you
try to upgrade the versions i told you, to support Hibernate without any
changes (it's because our old applications are used to it).

Best regards,

Jens


Hi altogether,

i am using OpenEJB 3.x as standalone edition for JUnit tests and i tried to
get OpenEJB Examples running on Tomcat 6.0.x. on Oracle 10g.

I have problems configuring the persistence units and/or datasources. I am
not quite sure what the problem is:

persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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">
	<!--
	only one persistence unit per project by JPA Tools supported
	-->
	<!--
	<persistence-unit name="JPATestProject">
	</persistence-unit>
	-->
	<persistence-unit name="beds_pu" transaction-type="JTA">
		<provider>org.hibernate.ejb.HibernatePersistence</provider>
		<jta-data-source>OracleORCL</jta-data-source>
		<non-jta-data-source>OracleORCLUnmanaged</non-jta-data-source> 
        <class>info.toerber.beds.model.Test</class>
	</persistence-unit>
</persistence>

in one of my session beans i am declaring a datasource like:
@Resource(name="OracleORCL")
    DataSource dataSource;

In standalone for JUnit-Test it seems to be that OpenEJB always takes its
default Database HSQL.
Is this correct?
Is it possible to change this to an Oracle Datasource?

here is my openejb.xml in META-INF for standalone and in <tomcat>/conf for
Tomcat deployment:
<openejb>
	<Resource id="OracleORCL" type="DataSource">
    #  Oracle example
    #
    #  This connector will not work until you download the driver at:
    #  http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html
    JdbcDriver  oracle.jdbc.OracleDriver
    JdbcUrl     jdbc:oracle:thin:@192.168.2.96:1521:ORCL
    UserName    openejb
    Password    openejb
	JtaManaged true
</Resource>
<Resource id="OracleORCLUnmanaged" type="DataSource">
    #  Oracle example
    #
    #  This connector will not work until you download the driver at:
    #  http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html
    JdbcDriver  oracle.jdbc.OracleDriver
    JdbcUrl     jdbc:oracle:thin:@192.168.2.96:1521:ORCL
    UserName    openejb
    Password    openejb
	JtaManaged  false
</Resource>
</openejb>

The examples are running in Tomcat, but always on HSQL as i can see with

if (this.entityManager != null) {
				Object delegate = this.entityManager.getDelegate();
				if (delegate instanceof HibernateEntityManager) {
						HibernateEntityManager hibernateEntityManager =
(HibernateEntityManager) delegate;
						Session s = hibernateEntityManager.getSession();
						Connection conn = s.connection();
						inspectConnection(conn);

private void inspectConnection(Connection conn) throws SQLException {
		DatabaseMetaData dataBaseMetaData = conn.getMetaData();
		// The drivers are included with OpenEJB 3.0 and HSQLDB is the default
database.
		System.out.println(dataBaseMetaData.getDatabaseMajorVersion());
		System.out.println(dataBaseMetaData.getDatabaseMinorVersion());
		System.out.println(dataBaseMetaData.getDatabaseProductName());
		System.out.println(dataBaseMetaData.getDatabaseProductVersion());
		System.out.println(dataBaseMetaData.getDefaultTransactionIsolation());
		System.out.println(dataBaseMetaData.getDriverMajorVersion());
		System.out.println(dataBaseMetaData.getDriverMinorVersion());
		System.out.println(dataBaseMetaData.getDriverName());
		System.out.println(dataBaseMetaData.getDriverVersion());

I could change the default Persistence Provider, but it's not running on my
Oracle Datasource.
Looked in the documentation and i can see that HSQL is the default database.
But how and where can i change it always or for a specific persistence unit
or for a resource in standalone and/or Tomcat?

Btw. the persistence unit works if i take this in Eclipse JPA Tools:
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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">
	<!--
	only one persistence unit per project by JPA Tools supported
	-->
	<!--
	<persistence-unit name="JPATestProject">
	</persistence-unit>
	-->
	<persistence-unit name="beds_pu" transaction-type="RESOURCE_LOCAL">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <!-- use persistence.xml right mouse Synchronize classes to get actual
list -->
      <class>info.toerber.beds.model.Test</class>
      <properties>
         <property name="hibernate.dialect"
value="org.hibernate.dialect.Oracle10gDialect"/>
         <property name="hibernate.connection.driver_class"
value="oracle.jdbc.OracleDriver"/>
         <property name="hibernate.connection.username" value="openejb"/>
         <property name="hibernate.connection.password" value="openejb"/>
         <property name="hibernate.connection.url"
value="jdbc:oracle:thin:@192.168.2.96:1521:ORCL"/>
         <property name="hibernate.max_fetch_depth" value="3"/>
         <!-- JPA Tools looks for this setting(?), so does not always drop
the table as announced -->
         <property name="hibernate.hbm2ddl.auto" value="update" />
       	 <!--
         creates table at start and drops at the end!!
         <property name="hibernate.hbm2ddl.auto" value="create-drop" />
       	 -->
         <!-- cache configuration
         <property
name="hibernate.ejb.classcache.org.hibernate.ejb.test.Item"
value="read-write"/>
         <property
name="hibernate.ejb.collectioncache.org.hibernate.ejb.test.Item.distributors"
value="read-write, RegionName"/>
         -->

         <!-- alternatively to <class> and <property> declarations, you can
use a regular hibernate.cfg.xml file -->
         <!-- property name="hibernate.ejb.cfgfile"
value="/org/hibernate/ejb/test/hibernate.cfg.xml"/ -->
      </properties>
   </persistence-unit>
</persistence>

Any help welcome.
Thanks in advance.

Jens Toerber

http://www.nabble.com/file/p21552884/TimerBean.java TimerBean.java 
http://www.nabble.com/file/p21552884/TimerBeanLocal.java TimerBeanLocal.java 
http://www.nabble.com/file/p21552884/TimerServletContextListener.java
TimerServletContextListener.java 
http://www.nabble.com/file/p21552884/TimerBeanLocalTest.java
TimerBeanLocalTest.java 
-- 
View this message in context: http://www.nabble.com/OpenEJB-on-Oracle-tp20294024p21552884.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: OpenEJB on Oracle

Posted by JensToerber <je...@juwimm.com>.
Hi,

got our production application running with Openejb on Tomcat.
We are using:
- Spring 2.5.1 (JndiObjectFactoryBean); we could replace this with @EJB
- Facelets with JSF 1.2
- Timer
- MDBs
- Hibernate as JPA provider
- Entity and Session Beans

Currently no problems.

We have a newsletter module, where we generate a lot of E-Mails and need
long running transactions. We still have to test this and some other stress
tests. I'll report the results.

Best regards,

Jens


JensToerber wrote:
> 
> Hi altogether,
> 
> i am using OpenEJB 3.x as standalone edition for JUnit tests and i tried
> to get OpenEJB Examples running on Tomcat 6.0.x. on Oracle 10g.
> 
> I have problems configuring the persistence units and/or datasources. I am
> not quite sure what the problem is:
> 
> persistence.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> <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">
> 	<!--
> 	only one persistence unit per project by JPA Tools supported
> 	-->
> 	<!--
> 	<persistence-unit name="JPATestProject">
> 	</persistence-unit>
> 	-->
> 	<persistence-unit name="beds_pu" transaction-type="JTA">
> 		<provider>org.hibernate.ejb.HibernatePersistence</provider>
> 		<jta-data-source>OracleORCL</jta-data-source>
> 		<non-jta-data-source>OracleORCLUnmanaged</non-jta-data-source> 
>         <class>info.toerber.beds.model.Test</class>
> 	</persistence-unit>
> </persistence>
> 
> in one of my session beans i am declaring a datasource like:
> @Resource(name="OracleORCL")
>     DataSource dataSource;
> 
> In standalone for JUnit-Test it seems to be that OpenEJB always takes its
> default Database HSQL.
> Is this correct?
> Is it possible to change this to an Oracle Datasource?
> 
> here is my openejb.xml in META-INF for standalone and in <tomcat>/conf for
> Tomcat deployment:
> <openejb>
> 	<Resource id="OracleORCL" type="DataSource">
>     #  Oracle example
>     #
>     #  This connector will not work until you download the driver at:
>     #  http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html
>     JdbcDriver  oracle.jdbc.OracleDriver
>     JdbcUrl     jdbc:oracle:thin:@192.168.2.96:1521:ORCL
>     UserName    openejb
>     Password    openejb
> 	JtaManaged true
> </Resource>
> <Resource id="OracleORCLUnmanaged" type="DataSource">
>     #  Oracle example
>     #
>     #  This connector will not work until you download the driver at:
>     #  http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html
>     JdbcDriver  oracle.jdbc.OracleDriver
>     JdbcUrl     jdbc:oracle:thin:@192.168.2.96:1521:ORCL
>     UserName    openejb
>     Password    openejb
> 	JtaManaged  false
> </Resource>
> </openejb>
> 
> The examples are running in Tomcat, but always on HSQL as i can see with
> 
> if (this.entityManager != null) {
> 				Object delegate = this.entityManager.getDelegate();
> 				if (delegate instanceof HibernateEntityManager) {
> 						HibernateEntityManager hibernateEntityManager =
> (HibernateEntityManager) delegate;
> 						Session s = hibernateEntityManager.getSession();
> 						Connection conn = s.connection();
> 						inspectConnection(conn);
> 
> private void inspectConnection(Connection conn) throws SQLException {
> 		DatabaseMetaData dataBaseMetaData = conn.getMetaData();
> 		// The drivers are included with OpenEJB 3.0 and HSQLDB is the default
> database.
> 		System.out.println(dataBaseMetaData.getDatabaseMajorVersion());
> 		System.out.println(dataBaseMetaData.getDatabaseMinorVersion());
> 		System.out.println(dataBaseMetaData.getDatabaseProductName());
> 		System.out.println(dataBaseMetaData.getDatabaseProductVersion());
> 		System.out.println(dataBaseMetaData.getDefaultTransactionIsolation());
> 		System.out.println(dataBaseMetaData.getDriverMajorVersion());
> 		System.out.println(dataBaseMetaData.getDriverMinorVersion());
> 		System.out.println(dataBaseMetaData.getDriverName());
> 		System.out.println(dataBaseMetaData.getDriverVersion());
> 
> I could change the default Persistence Provider, but it's not running on
> my Oracle Datasource.
> Looked in the documentation and i can see that HSQL is the default
> database. But how and where can i change it always or for a specific
> persistence unit or for a resource in standalone and/or Tomcat?
> 
> Btw. the persistence unit works if i take this in Eclipse JPA Tools:
> persistence.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> <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">
> 	<!--
> 	only one persistence unit per project by JPA Tools supported
> 	-->
> 	<!--
> 	<persistence-unit name="JPATestProject">
> 	</persistence-unit>
> 	-->
> 	<persistence-unit name="beds_pu" transaction-type="RESOURCE_LOCAL">
>       <provider>org.hibernate.ejb.HibernatePersistence</provider>
>       <!-- use persistence.xml right mouse Synchronize classes to get
> actual list -->
>       <class>info.toerber.beds.model.Test</class>
>       <properties>
>          <property name="hibernate.dialect"
> value="org.hibernate.dialect.Oracle10gDialect"/>
>          <property name="hibernate.connection.driver_class"
> value="oracle.jdbc.OracleDriver"/>
>          <property name="hibernate.connection.username" value="openejb"/>
>          <property name="hibernate.connection.password" value="openejb"/>
>          <property name="hibernate.connection.url"
> value="jdbc:oracle:thin:@192.168.2.96:1521:ORCL"/>
>          <property name="hibernate.max_fetch_depth" value="3"/>
>          <!-- JPA Tools looks for this setting(?), so does not always drop
> the table as announced -->
>          <property name="hibernate.hbm2ddl.auto" value="update" />
>        	 <!--
>          creates table at start and drops at the end!!
>          <property name="hibernate.hbm2ddl.auto" value="create-drop" />
>        	 -->
>          <!-- cache configuration
>          <property
> name="hibernate.ejb.classcache.org.hibernate.ejb.test.Item"
> value="read-write"/>
>          <property
> name="hibernate.ejb.collectioncache.org.hibernate.ejb.test.Item.distributors"
> value="read-write, RegionName"/>
>          -->
> 
>          <!-- alternatively to <class> and <property> declarations, you
> can use a regular hibernate.cfg.xml file -->
>          <!-- property name="hibernate.ejb.cfgfile"
> value="/org/hibernate/ejb/test/hibernate.cfg.xml"/ -->
>       </properties>
>    </persistence-unit>
> </persistence>
> 
> Any help welcome.
> Thanks in advance.
> 
> Jens Toerber
> 

-- 
View this message in context: http://www.nabble.com/OpenEJB-on-Oracle-tp20294024p21952439.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: OpenEJB on Oracle

Posted by David Blevins <da...@visi.com>.
On Jan 9, 2009, at 5:08 PM, JensToerber wrote:

> Tried to get my application running with Hibernate as JPA-Provider  
> on Tomcat
> with Openejb:
> Openejb is loaded during startup of Tomcat, hence the Classes in
> <openejb-webapp>\lib (yes lib) are loaded very early. Take care to  
> do the
> same Class Loading Order in your Development environment, otherwise  
> you
> can't compare the two infrastructures.
>
> There seems to be a problem with slf4j-api-1.3.1.jar and
> slf4j-jdk14-1.3.1.jar (part of Openejb 3.1).

Thanks for this note.  We don't use that library directly and after a  
little digging looks like it's a requirement for Apache CXF.  If you  
don't use web services, you can safely delete the openejb-cxf jar as  
well as these jars:

cxf-bundle-2.0.4-incubator.jar
  XmlSchema-1.3.2.jar
  neethi-2.0.2.jar
  saaj-impl-1.3.jar
  slf4j-api-1.3.1.jar
  slf4j-jdk14-1.3.1.jar
  wstx-asl-3.2.1.jar

If you do delete any of the above make sure you do delete the openejb- 
cxf-3.1.jar as it contains a META-INF service file that will cause us  
to load CXF and it's requirements.

> I had to update these to version 1.5.2. (otherwise LinkageError or  
> no such
> Method Error), because i use Hibernate-Entitymanager 3.4.0.GA and
> Hibernate-Annotations 3.4.0.GA (and the corresponding delivered  
> dependencies
> see below).
>
> I also had to copy all Hibernate jars into <openejb-webapp>\lib folder
> instead of in WEB-INF\lib (is this really intended?), otherwise you  
> get
> NoClassDef Found Error:

It's a side effect of the persistence unit needing to be available at  
a lower level than the webapp; it could be used by another webapp or  
ejb jar in the ear if their was one.  We could add something here if  
you had a pressing need for it and knew you weren't going to be using  
the persistence unit outside the webapp.

> As i wrote TimerService is working in JUnit-Tests, but not in Tomcat  
> with
> Openejb! It is initialized, but fires never. No special Openejb-Log- 
> Entry
> for this. Any idea about this?

No idea just from the description, but if you had a very small webapp  
that reproduced the issue we could take a look at it.

> With the Transaction-Openejb-Logging-Fix now transactions work.

Great.  We hope to get a 3.1.1 patch release out soon with that and a  
few other fixes we've been working on for an upcoming Geronimo release.

> Still have to test Mail Session. Additionally access to  
> InnermostConnection
> (we are using some features of the Oracle Driver).
>
> JSF 1.2 and EJB-Injection currently no problem.

Great!

-David


Re: OpenEJB on Oracle

Posted by JensToerber <je...@juwimm.com>.
Hi,

addition:

Tried to get my application running with Hibernate as JPA-Provider on Tomcat
with Openejb:
Openejb is loaded during startup of Tomcat, hence the Classes in
<openejb-webapp>\lib (yes lib) are loaded very early. Take care to do the
same Class Loading Order in your Development environment, otherwise you
can't compare the two infrastructures.

There seems to be a problem with slf4j-api-1.3.1.jar and
slf4j-jdk14-1.3.1.jar (part of Openejb 3.1).

I had to update these to version 1.5.2. (otherwise LinkageError or no such
Method Error), because i use Hibernate-Entitymanager 3.4.0.GA and
Hibernate-Annotations 3.4.0.GA (and the corresponding delivered dependencies
see below).

I also had to copy all Hibernate jars into <openejb-webapp>\lib folder
instead of in WEB-INF\lib (is this really intended?), otherwise you get
NoClassDef Found Error:

09.01.2009  23:10           443.432 antlr.jar
09.01.2009  23:10            26.360 asm.jar
09.01.2009  23:10           282.338 cglib.jar
09.01.2009  23:10           313.898 dom4j.jar
09.01.2009  23:10           279.714 hibernate-annotations.jar
09.01.2009  23:10            66.993 hibernate-commons-annotations.jar
09.01.2009  23:10         2.266.769 hibernate-core.jar
09.01.2009  23:10           119.292 hibernate-entitymanager.jar
10.01.2009  01:49                 0 hibernate.txt
09.01.2009  23:10           471.005 javassist.jar
09.01.2009  23:13               230 Readme_Hibernate.txt
09.01.2009  23:11            17.384 slf4j-api-1.5.2.jar
09.01.2009  23:11             8.643 slf4j-jdk14-1.5.2.jar

As i wrote TimerService is working in JUnit-Tests, but not in Tomcat with
Openejb! It is initialized, but fires never. No special Openejb-Log-Entry
for this. Any idea about this?

With the Transaction-Openejb-Logging-Fix now transactions work.

Still have to test Mail Session. Additionally access to InnermostConnection
(we are using some features of the Oracle Driver).

JSF 1.2 and EJB-Injection currently no problem. 

Best regards,

Jens


JensToerber wrote:
> 
> Hi David,
> 
> thanks a lot. Yes, had a little problems with my logging and some
> Openejb-Auto-Correction-Logging-Entries are a little bit confusing for me.
> 
> There are hopefully only 2 things left.
> 
> Currently i am assembling all hints together and then will try to get
> everything running on Tomcat with Openejb:
> 
> 1.) DataSource-Resource:
> You may specify connection properties. Is it possible to specify a SQL
> statement on new connection?
> The idea is to execute some ALTER SESSION ... statements for Oracle.
> 
> Ok i know and also read here that you may take an
> Oracle-Session-Logon-Trigger where you may execute some statements.
> And some things may be configurable via connection properties.
> We are used by JBoss to configure it in the JBoss *-ds.xml file
> <new-connection-sql/>.
> 
> 2.) javax.mail.Session:
> There is no property specified in the documentation for <Resource> in
> openejb.xml.
> Is it configured via System properties (hm, how about several applications
> querying using different servers) or does each client have to take care of
> the mail settings?
> Could not find very much about this topic.
> 
> Thanks in advance.
> 
> Best regards,
> 
> Jens
> 
> David Blevins wrote:
>> 
>> 
>> On Dec 28, 2008, at 2:12 PM, JensToerber wrote:
>> 
>>>
>>> Hi again,
>> 
>> Hi Jens!
>> 
>>> I did not manage to run OpenEJB on Oracle in JUnit-Test if i  
>>> configure it
>>> like this:
>>> p.put(DATASOURCE, "new://Resource?type=DataSource");
>>>        p.put(DATASOURCE + ".JdbcDriver", "oracle.jdbc.OracleDriver");
>>>        // it is not working thin driver is complaining about missing
>>> username and/or password
>>>        // p.put(DATASOURCE + ".JdbcUrl", "jdbc:oracle:thin:" +  
>>> USERNAME +
>>> "/" + PASSWORD + "@192.168.2.96:1521:ORCL");
>>>        p.put(DATASOURCE + ".JdbcUrl", "jdbc:oracle:thin:" + USERNAME  
>>> + "/"
>>> + PASSWORD + "@192.168.2.99:1521:XE");
>>>        p.put("oracle.jdbc.user", USERNAME);
>>>        p.put("oracle.jdbc.username", USERNAME);
>>>        p.put("oracle.jdbc.password", PASSWORD);
>>>        p.put("user", "openejb");
>>>        p.put("password", "openejb");
>>>        p.put(DATASOURCE + ".JdbcUsername", "openejb");
>>>        p.put(DATASOURCE + ".JdbcPassword", "openejb");
>>>        // openejb always sets the username to sa and password to ""
>> 
>> You'll want to specify the "username" and "password" properties as  
>> follows:
>> 
>>          p.put("Oracle", "new://Resource?type=DataSource");
>>          p.put("Oracle.JdbcDriver", "oracle.jdbc.OracleDriver");
>>          p.put("Oracle.JdbcUrl", "jdbc:oracle:thin: 
>> 192.168.2.99:1521:XE");
>>          p.put("Oracle.Username", "foo");
>>          p.put("Oracle.Password", "bar");
>> 
>> Or if you want to use a "DATASOURCE" variable as you showed in your  
>> code then like this:
>> 
>>          String DATASOURCE = "Oracle";
>>          String USERNAME = "foo";
>>          String PASSWORD = "bar";
>> 
>>          p.put(DATASOURCE, "new://Resource?type=DataSource");
>>          p.put(DATASOURCE + ".JdbcDriver", "oracle.jdbc.OracleDriver");
>>          p.put(DATASOURCE + ".JdbcUrl", "jdbc:oracle:thin: 
>> 192.168.2.99:1521:XE");
>>          p.put(DATASOURCE + ".Username", USERNAME);
>>          p.put(DATASOURCE + ".Password", PASSWORD);
>> 
>> Note that all properties are not case-sensitive, so "username" and  
>> "password" will work as will "UsErNaMe" and "pAsSwOrD" and so on.
>> 
>> With the way you have it configured, you should see these four  
>> warnings in your log file saying that your guesses are not correct:
>> 
>>      WARN - Property "JdbcUsername" not supported by "Oracle"
>>      WARN - Property "jdbc.username" not supported by "Oracle"
>>      WARN - Property "JdbcPassword" not supported by "Oracle"
>>      WARN - Property "jdbc.user" not supported by "Oracle"
>>      WARN - Property "jdbc.password" not supported by "Oracle"
>> 
>>> Then i found something here to configure OpenEJB in JUnit-Tests via
>>> openejb.xml:
>>> Properties properties = getProperties();
>>> 	
>>> 	        URL config =
>>> this.getClass().getClassLoader().getResource("META-INF/openejb.xml");
>>> 	        properties.setProperty("openejb.configuration",
>>> config.toExternalForm());
>>> 	
>>> 	        Context retContext = null;
>>> 	
>>> 	        try {
>>> 				retContext = new InitialContext(properties);
>>>
>>> 	       ...
>>>
>>> Then Oracle Datasource is working in JUnit-Tests.
>>> Fine.
>> 
>> That's also a fine way to configure things for a test case.
>> 
>>> Got Timer running in OpenEJB JUnit-Test. It's straight forward.
>> 
>> Great!
>> 
>>> I tried to get an MDB running. This is working now in my JBoss  
>>> (without
>>> OpenEJB), not yet tested in Tomcat with OpenEJB, but it is not  
>>> working in
>>> OpenEJB-JUnit-Test.
>>>
>>> Initialization is working, OpenEJB does not complain about missing  
>>> Queue in
>>> configuration.
>>>
>>> I don't know if it should work in JUnit-Test.
>>> Here my inspection code:
>>> obj = retContext.lookup("<queue>");
>>> 				if (obj instanceof ActiveMQQueue) {
>>> 					ActiveMQQueue activeMQQueue  = (ActiveMQQueue) obj;
>>> 					
>>> 					String physicalName = activeMQQueue.getPhysicalName(); // value  
>>> of
>>> destination of openejb.xml - <Resource ...>destination ...</resource
>>> 					log.debug("physicalName: " + physicalName);
>>> 					String qualifiedName = activeMQQueue.getQualifiedName(); //
>>> queue://<physicalName>
>>> 					log.debug("qualifiedName: " + qualifiedName);					
>>> 					String destinationTypeAsString =
>>> activeMQQueue.getDestinationTypeAsString(); // Queue
>>> 					log.debug("destinationTypeAsString: " +  
>>> destinationTypeAsString);					
>>> 					// may throw JMSException:
>>> 					String queueName = activeMQQueue.getQueueName(); // equals to
>>> <physicalName> (?)
>>> 					log.debug("queueName: " + queueName);				
>>> 					Map options = activeMQQueue.getOptions(); // currently null
>>> 					log.debug("options: " + options);				
>>> 					Properties ps = activeMQQueue.getProperties();
>>> 					logProperties(ps);
>>> 					log.debug("ps: " + ps);				
>>> 				}
>>>
>>> I'll add my current openejb.xml file (for JUnit-Test).
>> 
>> Currently, you cannot lookup topics and queues directly inside a test  
>> case, you need to have an EJB (or servlet when in tomcat) lookup the  
>> topic or queue and pass it back.
>> 
>> This can be quite easy, however, by just including a bean as an inner  
>> class that declares dependencies on the resources you need.  For  
>> example:
>> 
>> public class MessagingTest extends TestCase {
>> 
>>      public void test() throws Exception {
>>          Properties p = new Properties();
>>          p.put(Context.INITIAL_CONTEXT_FACTORY,  
>> "org.apache.openejb.client.LocalInitialContextFactory");
>>          InitialContext context = new InitialContext(p);
>> 
>>          TestClient bean = (TestClient)  
>> context.lookup("TestClientBeanLocal");
>> 
>>          ConnectionFactory connectionFactory =  
>> bean.getConnectionFactory();
>> 
>>          Queue questionQueue = bean.getQueue();
>> 
>>          Connection connection = null;
>>          Session session = null;
>> 
>>          try {
>>              connection = connectionFactory.createConnection();
>>              connection.start();
>> 
>>              // Create a Session
>>              session = connection.createSession(false,  
>> Session.AUTO_ACKNOWLEDGE);
>> 
>>              // Create a MessageProducer from the Session to the Topic  
>> or Queue
>>              MessageProducer producer =  
>> session.createProducer(questionQueue);
>>              producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
>> 
>>              // Create a message
>>              TextMessage message = session.createTextMessage("Hello  
>> World");
>> 
>>              // Tell the producer to send the message
>>              producer.send(message);
>>          } finally {
>>              // Clean up
>>              if (session != null) session.close();
>>              if (connection != null) connection.close();
>>          }
>> 
>>      }
>> 
>>      @Stateless
>>      public static class TestClientBean implements TestClient {
>> 
>>          @Resource
>>          private ConnectionFactory connectionFactory;
>> 
>>          @Resource(name = "FooQueue")
>>          private Queue queue;
>> 
>>          public ConnectionFactory getConnectionFactory() {
>>              return connectionFactory;
>>          }
>> 
>>          public Queue getQueue() {
>>              return queue;
>>          }
>>      }
>> 
>>      public interface TestClient {
>> 
>>          public ConnectionFactory getConnectionFactory();
>> 
>>          public Queue getQueue();
>>      }
>> }
>> 
>> For this to work you'll need to add a META-INF/ejb-jar.xml to your  
>> test sources directory (src/test/resources/ for Maven).  We'll then  
>> scrape your test classes for ejbs as well and process them with your  
>> other applications.  Quite a lot of interesting testing techniques can  
>> be done this way.
>> 
>> 
>>> Currenlty i am not quite sure how to configure an ActiveMQ  
>>> persistent Queue
>>> in OpenEJB.
>>>
>>> ActiveMQ creates the Destination on the fly. In JBoss you have to  
>>> configure
>>> Queues in advance to be persistent. Non-persistent are created on  
>>> the fly.
>>>
>>> There is a service-jar.xml in openejb.war\org.apache.openejb.tomcat 
>>> \META-INF
>>> or openejb.war\WEB-INF\classes\META-INF\org.apache.openejb.tomcat 
>>> \META-INF.
>> 
>> The service-jar.xml is there to specify the default values for  
>> properties that haven't been explicitly configured the user.  We use a  
>> different service-jar.xml for unit testing that we do for usage in  
>> Tomcat, for example.  In unit testing the service-jar.xml sets up a  
>> profile that by default will not open any ports or consume any disk  
>> (i.e. no embedded database files and no persistence message stores).   
>> In Tomcat the service-jar.xml sets up a profile that by default will  
>> open ports for things like the message broker and also use disk for  
>> persistence message stores.
>> 
>> But as mentioned, this only affects the defaults when not specified.   
>> In all cases you can set things up explicitly how you would like  
>> them.  Here's how you would setup ActiveMQ for more of an online mode:
>> 
>> <Resource id="MyJMSResourceAdapter" type="ActiveMQResourceAdapter">
>>    # Broker configuration URI as defined by ActiveMQ
>>    # see http://activemq.apache.org/broker-configuration-uri.html
>>    BrokerXmlConfig = broker:(tcp://localhost:61616)?useJmx=false
>> 
>>    # Broker address
>>    ServerUrl = tcp://localhost:61616
>> 
>>    # DataSource for persistence messages, should be the "id" of a  
>> <Resource> of type DataSource
>>    DataSource = MyDataSource
>> </Resource>
>> 
>> 
>> Here's a more offline mode which we typically recommend for test cases  
>> as all clients are in the same VM.  No ports will be opened with this  
>> configuration:
>> 
>> <Resource id="MyJMSResourceAdapter" type="ActiveMQResourceAdapter">
>>    # Broker configuration URI as defined by ActiveMQ
>>    # see http://activemq.apache.org/broker-configuration-uri.html
>>    BrokerXmlConfig = broker:()/localhost?persistent=false
>> 
>>    # Broker address
>>    ServerUrl = vm://localhost?async=true
>> 
>>    # DataSource for persistence messages, should be the "id" of a  
>> <Resource> of type DataSource
>>    DataSource = MyDataSource
>> </Resource>
>> 
>> 
>> -David
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/OpenEJB-on-Oracle-tp20294024p21383484.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: OpenEJB on Oracle

Posted by David Blevins <da...@visi.com>.
On Jan 9, 2009, at 4:35 AM, JensToerber wrote:

>
> Hi David,
>
> thanks a lot. Yes, had a little problems with my logging and some
> Openejb-Auto-Correction-Logging-Entries are a little bit confusing  
> for me.

Definitely let us know what things tripped you up and what you found  
confusing regarding the logging and auto-correction.  Likely something  
we can add/change/document.

> There are hopefully only 2 things left.
>
> Currently i am assembling all hints together and then will try to get
> everything running on Tomcat with Openejb:
>
> 1.) DataSource-Resource:
> You may specify connection properties. Is it possible to specify a SQL
> statement on new connection?
> The idea is to execute some ALTER SESSION ... statements for Oracle.
>
> Ok i know and also read here that you may take an
> Oracle-Session-Logon-Trigger where you may execute some statements.
> And some things may be configurable via connection properties.
> We are used by JBoss to configure it in the JBoss *-ds.xml file
> <new-connection-sql/>.

So if I understand correctly you're looking for some functionality  
that allows you to statically configure some sql statements that will  
be executed when we create new connections?

> 2.) javax.mail.Session:
> There is no property specified in the documentation for <Resource> in
> openejb.xml.
> Is it configured via System properties (hm, how about several  
> applications
> querying using different servers) or does each client have to take  
> care of
> the mail settings?
> Could not find very much about this topic.

We should definitely document this more.  The basics are that any  
properties listed in the <Resource> element are given directly to the  
javamail provider via javax.mail.Session.getDefaultInstance(Properties  
props).

Here might be some example properties.

<Resource id="SuperbizMail" type="javax.mail.Session">
     mail.smtp.host="mail.superbiz.org"
     mail.smtp.port="25"
     mail.transport.protocol="smtp"
     mail.smtp.auth="true"
     mail.smtp.user="someuser"
     password="mypassword"
</Resource>

You can create as many <Resource> entries like this as you wish, they  
just have to have a unique 'id'.  If you wanted to do a system  
property or initialcontext property override of the above example mail  
session, you could do so like this:

  java ... -DSuperbizMail.mail.smtp.host=localhost

Let us know if you find that useful and we can just take this example  
and add it straight to the docs (feel free to add details for that  
purpose as well).

-David



Re: OpenEJB on Oracle

Posted by JensToerber <je...@juwimm.com>.
Hi David,

thanks a lot. Yes, had a little problems with my logging and some
Openejb-Auto-Correction-Logging-Entries are a little bit confusing for me.

There are hopefully only 2 things left.

Currently i am assembling all hints together and then will try to get
everything running on Tomcat with Openejb:

1.) DataSource-Resource:
You may specify connection properties. Is it possible to specify a SQL
statement on new connection?
The idea is to execute some ALTER SESSION ... statements for Oracle.

Ok i know and also read here that you may take an
Oracle-Session-Logon-Trigger where you may execute some statements.
And some things may be configurable via connection properties.
We are used by JBoss to configure it in the JBoss *-ds.xml file
<new-connection-sql/>.

2.) javax.mail.Session:
There is no property specified in the documentation for <Resource> in
openejb.xml.
Is it configured via System properties (hm, how about several applications
querying using different servers) or does each client have to take care of
the mail settings?
Could not find very much about this topic.

Thanks in advance.

Best regards,

Jens

David Blevins wrote:
> 
> 
> On Dec 28, 2008, at 2:12 PM, JensToerber wrote:
> 
>>
>> Hi again,
> 
> Hi Jens!
> 
>> I did not manage to run OpenEJB on Oracle in JUnit-Test if i  
>> configure it
>> like this:
>> p.put(DATASOURCE, "new://Resource?type=DataSource");
>>        p.put(DATASOURCE + ".JdbcDriver", "oracle.jdbc.OracleDriver");
>>        // it is not working thin driver is complaining about missing
>> username and/or password
>>        // p.put(DATASOURCE + ".JdbcUrl", "jdbc:oracle:thin:" +  
>> USERNAME +
>> "/" + PASSWORD + "@192.168.2.96:1521:ORCL");
>>        p.put(DATASOURCE + ".JdbcUrl", "jdbc:oracle:thin:" + USERNAME  
>> + "/"
>> + PASSWORD + "@192.168.2.99:1521:XE");
>>        p.put("oracle.jdbc.user", USERNAME);
>>        p.put("oracle.jdbc.username", USERNAME);
>>        p.put("oracle.jdbc.password", PASSWORD);
>>        p.put("user", "openejb");
>>        p.put("password", "openejb");
>>        p.put(DATASOURCE + ".JdbcUsername", "openejb");
>>        p.put(DATASOURCE + ".JdbcPassword", "openejb");
>>        // openejb always sets the username to sa and password to ""
> 
> You'll want to specify the "username" and "password" properties as  
> follows:
> 
>          p.put("Oracle", "new://Resource?type=DataSource");
>          p.put("Oracle.JdbcDriver", "oracle.jdbc.OracleDriver");
>          p.put("Oracle.JdbcUrl", "jdbc:oracle:thin: 
> 192.168.2.99:1521:XE");
>          p.put("Oracle.Username", "foo");
>          p.put("Oracle.Password", "bar");
> 
> Or if you want to use a "DATASOURCE" variable as you showed in your  
> code then like this:
> 
>          String DATASOURCE = "Oracle";
>          String USERNAME = "foo";
>          String PASSWORD = "bar";
> 
>          p.put(DATASOURCE, "new://Resource?type=DataSource");
>          p.put(DATASOURCE + ".JdbcDriver", "oracle.jdbc.OracleDriver");
>          p.put(DATASOURCE + ".JdbcUrl", "jdbc:oracle:thin: 
> 192.168.2.99:1521:XE");
>          p.put(DATASOURCE + ".Username", USERNAME);
>          p.put(DATASOURCE + ".Password", PASSWORD);
> 
> Note that all properties are not case-sensitive, so "username" and  
> "password" will work as will "UsErNaMe" and "pAsSwOrD" and so on.
> 
> With the way you have it configured, you should see these four  
> warnings in your log file saying that your guesses are not correct:
> 
>      WARN - Property "JdbcUsername" not supported by "Oracle"
>      WARN - Property "jdbc.username" not supported by "Oracle"
>      WARN - Property "JdbcPassword" not supported by "Oracle"
>      WARN - Property "jdbc.user" not supported by "Oracle"
>      WARN - Property "jdbc.password" not supported by "Oracle"
> 
>> Then i found something here to configure OpenEJB in JUnit-Tests via
>> openejb.xml:
>> Properties properties = getProperties();
>> 	
>> 	        URL config =
>> this.getClass().getClassLoader().getResource("META-INF/openejb.xml");
>> 	        properties.setProperty("openejb.configuration",
>> config.toExternalForm());
>> 	
>> 	        Context retContext = null;
>> 	
>> 	        try {
>> 				retContext = new InitialContext(properties);
>>
>> 	       ...
>>
>> Then Oracle Datasource is working in JUnit-Tests.
>> Fine.
> 
> That's also a fine way to configure things for a test case.
> 
>> Got Timer running in OpenEJB JUnit-Test. It's straight forward.
> 
> Great!
> 
>> I tried to get an MDB running. This is working now in my JBoss  
>> (without
>> OpenEJB), not yet tested in Tomcat with OpenEJB, but it is not  
>> working in
>> OpenEJB-JUnit-Test.
>>
>> Initialization is working, OpenEJB does not complain about missing  
>> Queue in
>> configuration.
>>
>> I don't know if it should work in JUnit-Test.
>> Here my inspection code:
>> obj = retContext.lookup("<queue>");
>> 				if (obj instanceof ActiveMQQueue) {
>> 					ActiveMQQueue activeMQQueue  = (ActiveMQQueue) obj;
>> 					
>> 					String physicalName = activeMQQueue.getPhysicalName(); // value  
>> of
>> destination of openejb.xml - <Resource ...>destination ...</resource
>> 					log.debug("physicalName: " + physicalName);
>> 					String qualifiedName = activeMQQueue.getQualifiedName(); //
>> queue://<physicalName>
>> 					log.debug("qualifiedName: " + qualifiedName);					
>> 					String destinationTypeAsString =
>> activeMQQueue.getDestinationTypeAsString(); // Queue
>> 					log.debug("destinationTypeAsString: " +  
>> destinationTypeAsString);					
>> 					// may throw JMSException:
>> 					String queueName = activeMQQueue.getQueueName(); // equals to
>> <physicalName> (?)
>> 					log.debug("queueName: " + queueName);				
>> 					Map options = activeMQQueue.getOptions(); // currently null
>> 					log.debug("options: " + options);				
>> 					Properties ps = activeMQQueue.getProperties();
>> 					logProperties(ps);
>> 					log.debug("ps: " + ps);				
>> 				}
>>
>> I'll add my current openejb.xml file (for JUnit-Test).
> 
> Currently, you cannot lookup topics and queues directly inside a test  
> case, you need to have an EJB (or servlet when in tomcat) lookup the  
> topic or queue and pass it back.
> 
> This can be quite easy, however, by just including a bean as an inner  
> class that declares dependencies on the resources you need.  For  
> example:
> 
> public class MessagingTest extends TestCase {
> 
>      public void test() throws Exception {
>          Properties p = new Properties();
>          p.put(Context.INITIAL_CONTEXT_FACTORY,  
> "org.apache.openejb.client.LocalInitialContextFactory");
>          InitialContext context = new InitialContext(p);
> 
>          TestClient bean = (TestClient)  
> context.lookup("TestClientBeanLocal");
> 
>          ConnectionFactory connectionFactory =  
> bean.getConnectionFactory();
> 
>          Queue questionQueue = bean.getQueue();
> 
>          Connection connection = null;
>          Session session = null;
> 
>          try {
>              connection = connectionFactory.createConnection();
>              connection.start();
> 
>              // Create a Session
>              session = connection.createSession(false,  
> Session.AUTO_ACKNOWLEDGE);
> 
>              // Create a MessageProducer from the Session to the Topic  
> or Queue
>              MessageProducer producer =  
> session.createProducer(questionQueue);
>              producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
> 
>              // Create a message
>              TextMessage message = session.createTextMessage("Hello  
> World");
> 
>              // Tell the producer to send the message
>              producer.send(message);
>          } finally {
>              // Clean up
>              if (session != null) session.close();
>              if (connection != null) connection.close();
>          }
> 
>      }
> 
>      @Stateless
>      public static class TestClientBean implements TestClient {
> 
>          @Resource
>          private ConnectionFactory connectionFactory;
> 
>          @Resource(name = "FooQueue")
>          private Queue queue;
> 
>          public ConnectionFactory getConnectionFactory() {
>              return connectionFactory;
>          }
> 
>          public Queue getQueue() {
>              return queue;
>          }
>      }
> 
>      public interface TestClient {
> 
>          public ConnectionFactory getConnectionFactory();
> 
>          public Queue getQueue();
>      }
> }
> 
> For this to work you'll need to add a META-INF/ejb-jar.xml to your  
> test sources directory (src/test/resources/ for Maven).  We'll then  
> scrape your test classes for ejbs as well and process them with your  
> other applications.  Quite a lot of interesting testing techniques can  
> be done this way.
> 
> 
>> Currenlty i am not quite sure how to configure an ActiveMQ  
>> persistent Queue
>> in OpenEJB.
>>
>> ActiveMQ creates the Destination on the fly. In JBoss you have to  
>> configure
>> Queues in advance to be persistent. Non-persistent are created on  
>> the fly.
>>
>> There is a service-jar.xml in openejb.war\org.apache.openejb.tomcat 
>> \META-INF
>> or openejb.war\WEB-INF\classes\META-INF\org.apache.openejb.tomcat 
>> \META-INF.
> 
> The service-jar.xml is there to specify the default values for  
> properties that haven't been explicitly configured the user.  We use a  
> different service-jar.xml for unit testing that we do for usage in  
> Tomcat, for example.  In unit testing the service-jar.xml sets up a  
> profile that by default will not open any ports or consume any disk  
> (i.e. no embedded database files and no persistence message stores).   
> In Tomcat the service-jar.xml sets up a profile that by default will  
> open ports for things like the message broker and also use disk for  
> persistence message stores.
> 
> But as mentioned, this only affects the defaults when not specified.   
> In all cases you can set things up explicitly how you would like  
> them.  Here's how you would setup ActiveMQ for more of an online mode:
> 
> <Resource id="MyJMSResourceAdapter" type="ActiveMQResourceAdapter">
>    # Broker configuration URI as defined by ActiveMQ
>    # see http://activemq.apache.org/broker-configuration-uri.html
>    BrokerXmlConfig = broker:(tcp://localhost:61616)?useJmx=false
> 
>    # Broker address
>    ServerUrl = tcp://localhost:61616
> 
>    # DataSource for persistence messages, should be the "id" of a  
> <Resource> of type DataSource
>    DataSource = MyDataSource
> </Resource>
> 
> 
> Here's a more offline mode which we typically recommend for test cases  
> as all clients are in the same VM.  No ports will be opened with this  
> configuration:
> 
> <Resource id="MyJMSResourceAdapter" type="ActiveMQResourceAdapter">
>    # Broker configuration URI as defined by ActiveMQ
>    # see http://activemq.apache.org/broker-configuration-uri.html
>    BrokerXmlConfig = broker:()/localhost?persistent=false
> 
>    # Broker address
>    ServerUrl = vm://localhost?async=true
> 
>    # DataSource for persistence messages, should be the "id" of a  
> <Resource> of type DataSource
>    DataSource = MyDataSource
> </Resource>
> 
> 
> -David
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/OpenEJB-on-Oracle-tp20294024p21371469.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: OpenEJB on Oracle

Posted by David Blevins <da...@visi.com>.
On Dec 28, 2008, at 2:12 PM, JensToerber wrote:

>
> Hi again,

Hi Jens!

> I did not manage to run OpenEJB on Oracle in JUnit-Test if i  
> configure it
> like this:
> p.put(DATASOURCE, "new://Resource?type=DataSource");
>        p.put(DATASOURCE + ".JdbcDriver", "oracle.jdbc.OracleDriver");
>        // it is not working thin driver is complaining about missing
> username and/or password
>        // p.put(DATASOURCE + ".JdbcUrl", "jdbc:oracle:thin:" +  
> USERNAME +
> "/" + PASSWORD + "@192.168.2.96:1521:ORCL");
>        p.put(DATASOURCE + ".JdbcUrl", "jdbc:oracle:thin:" + USERNAME  
> + "/"
> + PASSWORD + "@192.168.2.99:1521:XE");
>        p.put("oracle.jdbc.user", USERNAME);
>        p.put("oracle.jdbc.username", USERNAME);
>        p.put("oracle.jdbc.password", PASSWORD);
>        p.put("user", "openejb");
>        p.put("password", "openejb");
>        p.put(DATASOURCE + ".JdbcUsername", "openejb");
>        p.put(DATASOURCE + ".JdbcPassword", "openejb");
>        // openejb always sets the username to sa and password to ""

You'll want to specify the "username" and "password" properties as  
follows:

         p.put("Oracle", "new://Resource?type=DataSource");
         p.put("Oracle.JdbcDriver", "oracle.jdbc.OracleDriver");
         p.put("Oracle.JdbcUrl", "jdbc:oracle:thin: 
192.168.2.99:1521:XE");
         p.put("Oracle.Username", "foo");
         p.put("Oracle.Password", "bar");

Or if you want to use a "DATASOURCE" variable as you showed in your  
code then like this:

         String DATASOURCE = "Oracle";
         String USERNAME = "foo";
         String PASSWORD = "bar";

         p.put(DATASOURCE, "new://Resource?type=DataSource");
         p.put(DATASOURCE + ".JdbcDriver", "oracle.jdbc.OracleDriver");
         p.put(DATASOURCE + ".JdbcUrl", "jdbc:oracle:thin: 
192.168.2.99:1521:XE");
         p.put(DATASOURCE + ".Username", USERNAME);
         p.put(DATASOURCE + ".Password", PASSWORD);

Note that all properties are not case-sensitive, so "username" and  
"password" will work as will "UsErNaMe" and "pAsSwOrD" and so on.

With the way you have it configured, you should see these four  
warnings in your log file saying that your guesses are not correct:

     WARN - Property "JdbcUsername" not supported by "Oracle"
     WARN - Property "jdbc.username" not supported by "Oracle"
     WARN - Property "JdbcPassword" not supported by "Oracle"
     WARN - Property "jdbc.user" not supported by "Oracle"
     WARN - Property "jdbc.password" not supported by "Oracle"

> Then i found something here to configure OpenEJB in JUnit-Tests via
> openejb.xml:
> Properties properties = getProperties();
> 	
> 	        URL config =
> this.getClass().getClassLoader().getResource("META-INF/openejb.xml");
> 	        properties.setProperty("openejb.configuration",
> config.toExternalForm());
> 	
> 	        Context retContext = null;
> 	
> 	        try {
> 				retContext = new InitialContext(properties);
>
> 	       ...
>
> Then Oracle Datasource is working in JUnit-Tests.
> Fine.

That's also a fine way to configure things for a test case.

> Got Timer running in OpenEJB JUnit-Test. It's straight forward.

Great!

> I tried to get an MDB running. This is working now in my JBoss  
> (without
> OpenEJB), not yet tested in Tomcat with OpenEJB, but it is not  
> working in
> OpenEJB-JUnit-Test.
>
> Initialization is working, OpenEJB does not complain about missing  
> Queue in
> configuration.
>
> I don't know if it should work in JUnit-Test.
> Here my inspection code:
> obj = retContext.lookup("<queue>");
> 				if (obj instanceof ActiveMQQueue) {
> 					ActiveMQQueue activeMQQueue  = (ActiveMQQueue) obj;
> 					
> 					String physicalName = activeMQQueue.getPhysicalName(); // value  
> of
> destination of openejb.xml - <Resource ...>destination ...</resource
> 					log.debug("physicalName: " + physicalName);
> 					String qualifiedName = activeMQQueue.getQualifiedName(); //
> queue://<physicalName>
> 					log.debug("qualifiedName: " + qualifiedName);					
> 					String destinationTypeAsString =
> activeMQQueue.getDestinationTypeAsString(); // Queue
> 					log.debug("destinationTypeAsString: " +  
> destinationTypeAsString);					
> 					// may throw JMSException:
> 					String queueName = activeMQQueue.getQueueName(); // equals to
> <physicalName> (?)
> 					log.debug("queueName: " + queueName);				
> 					Map options = activeMQQueue.getOptions(); // currently null
> 					log.debug("options: " + options);				
> 					Properties ps = activeMQQueue.getProperties();
> 					logProperties(ps);
> 					log.debug("ps: " + ps);				
> 				}
>
> I'll add my current openejb.xml file (for JUnit-Test).

Currently, you cannot lookup topics and queues directly inside a test  
case, you need to have an EJB (or servlet when in tomcat) lookup the  
topic or queue and pass it back.

This can be quite easy, however, by just including a bean as an inner  
class that declares dependencies on the resources you need.  For  
example:

public class MessagingTest extends TestCase {

     public void test() throws Exception {
         Properties p = new Properties();
         p.put(Context.INITIAL_CONTEXT_FACTORY,  
"org.apache.openejb.client.LocalInitialContextFactory");
         InitialContext context = new InitialContext(p);

         TestClient bean = (TestClient)  
context.lookup("TestClientBeanLocal");

         ConnectionFactory connectionFactory =  
bean.getConnectionFactory();

         Queue questionQueue = bean.getQueue();

         Connection connection = null;
         Session session = null;

         try {
             connection = connectionFactory.createConnection();
             connection.start();

             // Create a Session
             session = connection.createSession(false,  
Session.AUTO_ACKNOWLEDGE);

             // Create a MessageProducer from the Session to the Topic  
or Queue
             MessageProducer producer =  
session.createProducer(questionQueue);
             producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

             // Create a message
             TextMessage message = session.createTextMessage("Hello  
World");

             // Tell the producer to send the message
             producer.send(message);
         } finally {
             // Clean up
             if (session != null) session.close();
             if (connection != null) connection.close();
         }

     }

     @Stateless
     public static class TestClientBean implements TestClient {

         @Resource
         private ConnectionFactory connectionFactory;

         @Resource(name = "FooQueue")
         private Queue queue;

         public ConnectionFactory getConnectionFactory() {
             return connectionFactory;
         }

         public Queue getQueue() {
             return queue;
         }
     }

     public interface TestClient {

         public ConnectionFactory getConnectionFactory();

         public Queue getQueue();
     }
}

For this to work you'll need to add a META-INF/ejb-jar.xml to your  
test sources directory (src/test/resources/ for Maven).  We'll then  
scrape your test classes for ejbs as well and process them with your  
other applications.  Quite a lot of interesting testing techniques can  
be done this way.


> Currenlty i am not quite sure how to configure an ActiveMQ  
> persistent Queue
> in OpenEJB.
>
> ActiveMQ creates the Destination on the fly. In JBoss you have to  
> configure
> Queues in advance to be persistent. Non-persistent are created on  
> the fly.
>
> There is a service-jar.xml in openejb.war\org.apache.openejb.tomcat 
> \META-INF
> or openejb.war\WEB-INF\classes\META-INF\org.apache.openejb.tomcat 
> \META-INF.

The service-jar.xml is there to specify the default values for  
properties that haven't been explicitly configured the user.  We use a  
different service-jar.xml for unit testing that we do for usage in  
Tomcat, for example.  In unit testing the service-jar.xml sets up a  
profile that by default will not open any ports or consume any disk  
(i.e. no embedded database files and no persistence message stores).   
In Tomcat the service-jar.xml sets up a profile that by default will  
open ports for things like the message broker and also use disk for  
persistence message stores.

But as mentioned, this only affects the defaults when not specified.   
In all cases you can set things up explicitly how you would like  
them.  Here's how you would setup ActiveMQ for more of an online mode:

<Resource id="MyJMSResourceAdapter" type="ActiveMQResourceAdapter">
   # Broker configuration URI as defined by ActiveMQ
   # see http://activemq.apache.org/broker-configuration-uri.html
   BrokerXmlConfig = broker:(tcp://localhost:61616)?useJmx=false

   # Broker address
   ServerUrl = tcp://localhost:61616

   # DataSource for persistence messages, should be the "id" of a  
<Resource> of type DataSource
   DataSource = MyDataSource
</Resource>


Here's a more offline mode which we typically recommend for test cases  
as all clients are in the same VM.  No ports will be opened with this  
configuration:

<Resource id="MyJMSResourceAdapter" type="ActiveMQResourceAdapter">
   # Broker configuration URI as defined by ActiveMQ
   # see http://activemq.apache.org/broker-configuration-uri.html
   BrokerXmlConfig = broker:()/localhost?persistent=false

   # Broker address
   ServerUrl = vm://localhost?async=true

   # DataSource for persistence messages, should be the "id" of a  
<Resource> of type DataSource
   DataSource = MyDataSource
</Resource>


-David


Re: OpenEJB on Oracle

Posted by JensToerber <je...@juwimm.com>.
Hi again,

because of time issues i changed temporarily back to JBoss with an EAR.
I will change this, when i am ready with the first step of development.

I changed to Hibernate in OpenEJB3.1-JUnit-Tests and it works fine so far.

What i found out:
I did not manage to run OpenEJB on Oracle in JUnit-Test if i configure it
like this:
p.put(DATASOURCE, "new://Resource?type=DataSource");
        p.put(DATASOURCE + ".JdbcDriver", "oracle.jdbc.OracleDriver");
        // it is not working thin driver is complaining about missing
username and/or password
        // p.put(DATASOURCE + ".JdbcUrl", "jdbc:oracle:thin:" + USERNAME +
"/" + PASSWORD + "@192.168.2.96:1521:ORCL");
        p.put(DATASOURCE + ".JdbcUrl", "jdbc:oracle:thin:" + USERNAME + "/"
+ PASSWORD + "@192.168.2.99:1521:XE");
        p.put("oracle.jdbc.user", USERNAME);
        p.put("oracle.jdbc.username", USERNAME);
        p.put("oracle.jdbc.password", PASSWORD);
        p.put("user", "openejb");
        p.put("password", "openejb");
        p.put(DATASOURCE + ".JdbcUsername", "openejb");
        p.put(DATASOURCE + ".JdbcPassword", "openejb");
        // openejb always sets the username to sa and password to ""
        
If you do something like this:

ds = (DataSource)retContext.lookup("java:/openejb/Resource/OracleORCL");
	        	BasicManagedDataSource bds = (BasicManagedDataSource) ds;
	        	// needed otherwise wrong username/password set
	        	bds.setUserName("openejb"); // before: "sa"
	        	bds.setPassword("openejb"); // before: ""
	        	// works but has currently no effect for standalone tests
	        	retContext.rebind("java:/openejb/Resource/OracleORCL", ds);
	        	
Then it temporarily works, but not for newly created Connections via
Persistence-Unit.

It seems that in this configuration case OpenEJB always sets the User to
"sa" and password to "".

Then i found something here to configure OpenEJB in JUnit-Tests via
openejb.xml:
Properties properties = getProperties(); 
	
	        URL config =  
this.getClass().getClassLoader().getResource("META-INF/openejb.xml"); 
	        properties.setProperty("openejb.configuration",
config.toExternalForm()); 
	
	        Context retContext = null;
	        
	        try {
				retContext = new InitialContext(properties);

	       ...

Then Oracle Datasource is working in JUnit-Tests.
Fine.

Got Timer running in OpenEJB JUnit-Test. It's straight forward.

I tried to get an MDB running. This is working now in my JBoss (without
OpenEJB), not yet tested in Tomcat with OpenEJB, but it is not working in
OpenEJB-JUnit-Test.

Initialization is working, OpenEJB does not complain about missing Queue in
configuration.

I don't know if it should work in JUnit-Test.
Here my inspection code:
obj = retContext.lookup("<queue>");
				if (obj instanceof ActiveMQQueue) {
					ActiveMQQueue activeMQQueue  = (ActiveMQQueue) obj;
					
					String physicalName = activeMQQueue.getPhysicalName(); // value of
destination of openejb.xml - <Resource ...>destination ...</resource 
					log.debug("physicalName: " + physicalName);
					String qualifiedName = activeMQQueue.getQualifiedName(); //
queue://<physicalName>
					log.debug("qualifiedName: " + qualifiedName);					
					String destinationTypeAsString =
activeMQQueue.getDestinationTypeAsString(); // Queue
					log.debug("destinationTypeAsString: " + destinationTypeAsString);					
					// may throw JMSException:
					String queueName = activeMQQueue.getQueueName(); // equals to
<physicalName> (?)
					log.debug("queueName: " + queueName);				
					Map options = activeMQQueue.getOptions(); // currently null
					log.debug("options: " + options);				
					Properties ps = activeMQQueue.getProperties();
					logProperties(ps);
					log.debug("ps: " + ps);				
				}

I'll add my current openejb.xml file (for JUnit-Test).

Currenlty i am not quite sure how to configure an ActiveMQ persistent Queue
in OpenEJB.

ActiveMQ creates the Destination on the fly. In JBoss you have to configure
Queues in advance to be persistent. Non-persistent are created on the fly.

There is a service-jar.xml in openejb.war\org.apache.openejb.tomcat\META-INF
or openejb.war\WEB-INF\classes\META-INF\org.apache.openejb.tomcat\META-INF.

Until now i had no time to test OpenEJB with
Transaction-Logger-Configuration-Workaround. I'll do this if i am ready with
my first step and try to get the application running on Tomcat with OpenEJB.

Best regards,

Jens Törber

David Blevins wrote:
> 
> (excuse the delay - vacation)
> 
> On Nov 22, 2008, at 6:54 AM, JensToerber wrote:
> 
>> Hint:
>> If you try to run it as openejb-3.1.war you get trouble with the
>> installer.jsp, because the install-Button there expects ContextPath
>> /openejb. It's better to run it as openejb.xml, because otherwise  
>> you get
>> several config files (openejb.xml and openejb-3.1.xml) in
>> conf/Catalina/localhost.
> 
> We'll have to make note of that somewhere.
> 
>> Still have to test this for persistent Messages. But this is the  
>> step after
>> the next step.
> 
> Let us know how that went.
> 
>> In the Examples i could change the JpaServlet to
>>
>> public class JpaServlet extends HttpServlet {
>>    @Resource(name = "OracleORCL", type = javax.sql.DataSource.class)
>>    private javax.sql.DataSource ds;
>>
>>    @PersistenceUnit(name = "jpa-example")
>>    private EntityManagerFactory emf; // only injected if not in a
>> container?
>>
>>    @PersistenceContext(name = "jpa-example")
>>    private EntityManager em;
>> ...
>>
>> Now the DataSource ds is injected and working on Oracle.
> 
> Great.
> 
>> But i don't get the EntityManager injected. It is always null. Don't  
>> know
>> why.
> 
> Per spec, servlets aren't allowed @PersistenceContext injection as the  
> context propagation models (TRANSACTION and EXTENDED) don't really fit  
> for a servlet.  Definitely something we should add a validation  
> message for so at the least you would get a warning saying it won't  
> work and why.
> 
>> But my call to categoryDaoLocal.persist(category) fails with no ending
>> exceptions like:
>>
>> http://localhost:8080/HotelWebProject/servlet/TestServletilterChain.java:206)
>>        at
>> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
>> alve.java:233)
> [...]
>>        at
>> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
>> 7)
>>        at java.lang.Thread.run(Thread.java:595)
>> Caused by: java.lang.IllegalArgumentException: can't parse argument  
>> number
>>        at java.text.MessageFormat.makeFormat(MessageFormat.java:1330)
>>        at java.text.MessageFormat.applyPattern(MessageFormat.java:450)
>>        at java.text.MessageFormat.<init>(MessageFormat.java:350)
>>        at org.apache.openejb.util.Logger$4.compute(Logger.java:108)
>>        at org.apache.openejb.util.Logger$4.compute(Logger.java:107)
>>        at org.apache.openejb.util.Memoizer$1.call(Memoizer.java:42)
>>        at
> [...]
> 
> An invalidly formatted i18n message text slipped into one of our  
> Messages.properties files right before the release went out.  This has  
> been fixed in the coming 3.1.1
> (https://issues.apache.org/jira/browse/OPENEJB-950 
> )
> 
> A workaround is to set the related logging category to ERROR:
> 
>    log4j.category.Transaction = ERROR
> 
>> Next steps then are:
>> - Get our application work (MyFaces 1.2, Facelets, Timer, MDBs with
>> persistent Messages on Tomcat Cluster hopefully with Openejb)
>> - try to change JPA-Provider to Hibernate (still haven't looked for
>> automatically database schema update in OpenJPA-Provider)
> 
> Let us know if you need any help with those.
> 
> -David
> 
> 
> 
http://www.nabble.com/file/p21196502/openejb.xml openejb.xml 

http://www.nabble.com/file/p21196600/SendEmailToUserMessageProducer.java
SendEmailToUserMessageProducer.java 
http://www.nabble.com/file/p21196600/SendEmailToUserMDB.java
SendEmailToUserMDB.java 
-- 
View this message in context: http://www.nabble.com/OpenEJB-on-Oracle-tp20294024p21196600.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: OpenEJB on Oracle

Posted by JensToerber <je...@juwimm.com>.
Hi again,

because of time issues i changed temporarily back to JBoss with an EAR.
I will change this, when i am ready with the first step of development.

What i found out:
I did not manage to run OpenEJB on Oracle in JUnit-Test if i configure it
like this:
p.put(DATASOURCE, "new://Resource?type=DataSource");
        p.put(DATASOURCE + ".JdbcDriver", "oracle.jdbc.OracleDriver");
        // it is not working thin driver is complaining about missing
username and/or password
        // p.put(DATASOURCE + ".JdbcUrl", "jdbc:oracle:thin:" + USERNAME +
"/" + PASSWORD + "@192.168.2.96:1521:ORCL");
        p.put(DATASOURCE + ".JdbcUrl", "jdbc:oracle:thin:" + USERNAME + "/"
+ PASSWORD + "@192.168.2.99:1521:XE");
        p.put("oracle.jdbc.user", USERNAME);
        p.put("oracle.jdbc.username", USERNAME);
        p.put("oracle.jdbc.password", PASSWORD);
        p.put("user", "openejb");
        p.put("password", "openejb");
        p.put(DATASOURCE + ".JdbcUsername", "openejb");
        p.put(DATASOURCE + ".JdbcPassword", "openejb");
        // openejb always sets the username to sa and password to ""
        
If you do something like this:

ds = (DataSource)retContext.lookup("java:/openejb/Resource/OracleORCL");
	        	BasicManagedDataSource bds = (BasicManagedDataSource) ds;
	        	// needed otherwise wrong username/password set
	        	bds.setUserName("openejb"); // before: "sa"
	        	bds.setPassword("openejb"); // before: ""
	        	// works but has currently no effect for standalone tests
	        	retContext.rebind("java:/openejb/Resource/OracleORCL", ds);
	        	
Then it temporarily works, but not for newly created Connections via
Persistence-Context.

It seems that in this configuration case OpenEJB always sets the User to
"sa" and password to "".

Then i found something here to configure OpenEJB in JUnit-Tests via
openejb.xml:
Properties properties = getProperties(); 
	
	        URL config =  
this.getClass().getClassLoader().getResource("META-INF/openejb.xml"); 
	        properties.setProperty("openejb.configuration",
config.toExternalForm()); 
	
	        Context retContext = null;
	        
	        try {
				retContext = new InitialContext(properties);

	       ...

Then Oracle Datasource is working in JUnit-Tests.
Fine.

Got Timer running in OpenEJB JUnit-Test. It's straight forward.

I tried to get an MDB running. This is working now in my JBoss (without
OpenEJB), not yet tested in Tomcat with OpenEJB, but it is not working in
OpenEJB-JUnit-Test.

Initialization is working, OpenEJB does not complain about missing Queue in
configuration.

I don't know if it should work in JUnit-Test.
Here my inspection code:
obj = retContext.lookup("<queue>");
				if (obj instanceof ActiveMQQueue) {
					ActiveMQQueue activeMQQueue  = (ActiveMQQueue) obj;
					
					String physicalName = activeMQQueue.getPhysicalName(); // value of
destination of openejb.xml - <Resource ...>destination ...</resource 
					log.debug("physicalName: " + physicalName);
					String qualifiedName = activeMQQueue.getQualifiedName(); //
queue://<physicalName>
					log.debug("qualifiedName: " + qualifiedName);					
					String destinationTypeAsString =
activeMQQueue.getDestinationTypeAsString(); // Queue
					log.debug("destinationTypeAsString: " + destinationTypeAsString);					
					// may throw JMSException:
					String queueName = activeMQQueue.getQueueName(); // equals to
<physicalName> (?)
					log.debug("queueName: " + queueName);				
					Map options = activeMQQueue.getOptions(); // currently null
					log.debug("options: " + options);				
					Properties ps = activeMQQueue.getProperties();
					logProperties(ps);
					log.debug("ps: " + ps);				
				}

I'll add my current openejb.xml file (for JUnit-Test).

Currenlty i am not quite sure how to configure an ActiveMQ persistent Queue
in OpenEJB.

ActiveMQ creates the Destination on the fly. In JBoss you have to configure
Queues in advance to be persistent. Non-persistent are created on the fly.

There is a service-jar.xml in openejb.war\org.apache.openejb.tomcat\META-INF
or openejb.war\WEB-INF\classes\META-INF\org.apache.openejb.tomcat\META-INF.

Until now i had no time to test OpenEJB with
Transaction-Logger-Configuration-Workaround. I'll do this if i am ready with
my first step and try to get the application running on Tomcat with OpenEJB.

Best regards,

Jens Törber

David Blevins wrote:
> 
> (excuse the delay - vacation)
> 
> On Nov 22, 2008, at 6:54 AM, JensToerber wrote:
> 
>> Hint:
>> If you try to run it as openejb-3.1.war you get trouble with the
>> installer.jsp, because the install-Button there expects ContextPath
>> /openejb. It's better to run it as openejb.xml, because otherwise  
>> you get
>> several config files (openejb.xml and openejb-3.1.xml) in
>> conf/Catalina/localhost.
> 
> We'll have to make note of that somewhere.
> 
>> Still have to test this for persistent Messages. But this is the  
>> step after
>> the next step.
> 
> Let us know how that went.
> 
>> In the Examples i could change the JpaServlet to
>>
>> public class JpaServlet extends HttpServlet {
>>    @Resource(name = "OracleORCL", type = javax.sql.DataSource.class)
>>    private javax.sql.DataSource ds;
>>
>>    @PersistenceUnit(name = "jpa-example")
>>    private EntityManagerFactory emf; // only injected if not in a
>> container?
>>
>>    @PersistenceContext(name = "jpa-example")
>>    private EntityManager em;
>> ...
>>
>> Now the DataSource ds is injected and working on Oracle.
> 
> Great.
> 
>> But i don't get the EntityManager injected. It is always null. Don't  
>> know
>> why.
> 
> Per spec, servlets aren't allowed @PersistenceContext injection as the  
> context propagation models (TRANSACTION and EXTENDED) don't really fit  
> for a servlet.  Definitely something we should add a validation  
> message for so at the least you would get a warning saying it won't  
> work and why.
> 
>> But my call to categoryDaoLocal.persist(category) fails with no ending
>> exceptions like:
>>
>> http://localhost:8080/HotelWebProject/servlet/TestServletilterChain.java:206)
>>        at
>> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
>> alve.java:233)
> [...]
>>        at
>> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
>> 7)
>>        at java.lang.Thread.run(Thread.java:595)
>> Caused by: java.lang.IllegalArgumentException: can't parse argument  
>> number
>>        at java.text.MessageFormat.makeFormat(MessageFormat.java:1330)
>>        at java.text.MessageFormat.applyPattern(MessageFormat.java:450)
>>        at java.text.MessageFormat.<init>(MessageFormat.java:350)
>>        at org.apache.openejb.util.Logger$4.compute(Logger.java:108)
>>        at org.apache.openejb.util.Logger$4.compute(Logger.java:107)
>>        at org.apache.openejb.util.Memoizer$1.call(Memoizer.java:42)
>>        at
> [...]
> 
> An invalidly formatted i18n message text slipped into one of our  
> Messages.properties files right before the release went out.  This has  
> been fixed in the coming 3.1.1
> (https://issues.apache.org/jira/browse/OPENEJB-950 
> )
> 
> A workaround is to set the related logging category to ERROR:
> 
>    log4j.category.Transaction = ERROR
> 
>> Next steps then are:
>> - Get our application work (MyFaces 1.2, Facelets, Timer, MDBs with
>> persistent Messages on Tomcat Cluster hopefully with Openejb)
>> - try to change JPA-Provider to Hibernate (still haven't looked for
>> automatically database schema update in OpenJPA-Provider)
> 
> Let us know if you need any help with those.
> 
> -David
> 
> 
> 
http://www.nabble.com/file/p21196502/openejb.xml openejb.xml 
-- 
View this message in context: http://www.nabble.com/OpenEJB-on-Oracle-tp20294024p21196502.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: OpenEJB on Oracle

Posted by David Blevins <da...@visi.com>.
(excuse the delay - vacation)

On Nov 22, 2008, at 6:54 AM, JensToerber wrote:

> Hint:
> If you try to run it as openejb-3.1.war you get trouble with the
> installer.jsp, because the install-Button there expects ContextPath
> /openejb. It's better to run it as openejb.xml, because otherwise  
> you get
> several config files (openejb.xml and openejb-3.1.xml) in
> conf/Catalina/localhost.

We'll have to make note of that somewhere.

> Still have to test this for persistent Messages. But this is the  
> step after
> the next step.

Let us know how that went.

> In the Examples i could change the JpaServlet to
>
> public class JpaServlet extends HttpServlet {
>    @Resource(name = "OracleORCL", type = javax.sql.DataSource.class)
>    private javax.sql.DataSource ds;
>
>    @PersistenceUnit(name = "jpa-example")
>    private EntityManagerFactory emf; // only injected if not in a
> container?
>
>    @PersistenceContext(name = "jpa-example")
>    private EntityManager em;
> ...
>
> Now the DataSource ds is injected and working on Oracle.

Great.

> But i don't get the EntityManager injected. It is always null. Don't  
> know
> why.

Per spec, servlets aren't allowed @PersistenceContext injection as the  
context propagation models (TRANSACTION and EXTENDED) don't really fit  
for a servlet.  Definitely something we should add a validation  
message for so at the least you would get a warning saying it won't  
work and why.

> But my call to categoryDaoLocal.persist(category) fails with no ending
> exceptions like:
>
> http://localhost:8080/HotelWebProject/servlet/TestServletilterChain.java:206)
>        at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
> alve.java:233)
[...]
>        at
> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
> 7)
>        at java.lang.Thread.run(Thread.java:595)
> Caused by: java.lang.IllegalArgumentException: can't parse argument  
> number
>        at java.text.MessageFormat.makeFormat(MessageFormat.java:1330)
>        at java.text.MessageFormat.applyPattern(MessageFormat.java:450)
>        at java.text.MessageFormat.<init>(MessageFormat.java:350)
>        at org.apache.openejb.util.Logger$4.compute(Logger.java:108)
>        at org.apache.openejb.util.Logger$4.compute(Logger.java:107)
>        at org.apache.openejb.util.Memoizer$1.call(Memoizer.java:42)
>        at
[...]

An invalidly formatted i18n message text slipped into one of our  
Messages.properties files right before the release went out.  This has  
been fixed in the coming 3.1.1 (https://issues.apache.org/jira/browse/OPENEJB-950 
)

A workaround is to set the related logging category to ERROR:

   log4j.category.Transaction = ERROR

> Next steps then are:
> - Get our application work (MyFaces 1.2, Facelets, Timer, MDBs with
> persistent Messages on Tomcat Cluster hopefully with Openejb)
> - try to change JPA-Provider to Hibernate (still haven't looked for
> automatically database schema update in OpenJPA-Provider)

Let us know if you need any help with those.

-David


Re: OpenEJB on Oracle

Posted by JensToerber <je...@juwimm.com>.
Hi again,

i got it partly working on Oracle database.

My problem was, that my <Resource .../>.declaration in openejb.xml was wrong
(Tomcat-Resource style, shame on me, but good to have the xsd now) and
openejb switched to the default datasource. I don't know if i like this
behaviour with no at least WARN entry in openejb.log.

I upgraded to openejb-3.1 now.

Hint:
If you try to run it as openejb-3.1.war you get trouble with the
installer.jsp, because the install-Button there expects ContextPath
/openejb. It's better to run it as openejb.xml, because otherwise you get
several config files (openejb.xml and openejb-3.1.xml) in
conf/Catalina/localhost.

Now i have the attached config: openejb.xml

As you can see i removed the default datasources and added my Oracle
datasources. If you remove the default datasources you also have to
configure ActiveMQ for the new Datasource:
See
...
<Resource id="My JMS Resource Adapter" type="ActiveMQResourceAdapter">
...

Still have to test this for persistent Messages. But this is the step after
the next step.

In the Examples i could change the JpaServlet to

public class JpaServlet extends HttpServlet {
    @Resource(name = "OracleORCL", type = javax.sql.DataSource.class)
    private javax.sql.DataSource ds;
    
    @PersistenceUnit(name = "jpa-example")
    private EntityManagerFactory emf; // only injected if not in a
container?
    
    @PersistenceContext(name = "jpa-example")
    private EntityManager em;
...

Now the DataSource ds is injected and working on Oracle.

But i don't get the EntityManager injected. It is always null. Don't know
why.

In the Examples the JpaBean is not working on Oracle, because the
GeneratorType is AUTO -> IDENTITY. I switched this to Sequence, otherwise
you need a trigger or something like that on the Oracle table to generate
the Primary Key-Value.

Therefore the JpaServlet-Sample is designed for RESOURCE_LOCAL
(emf.createEntityManager() is called) and for Databases with AUTO-Increment
PKs.

Then i tried to get my application working.
Injection in MyFaces 1.2.x (downloaded dummy.war by K??) and Servlet of
Local-Stateless SessionBean is working or JNDI-Lookup:

@EJB(beanName="CategoryDao")
	private CategoryDaoLocal categoryDaoLocal;
	
	public CategoryDaoLocal getCategoryDaoLocal() {
		return categoryDaoLocal;
	}

	public void setCategoryDaoLocal(CategoryDaoLocal categoryDaoLocal) {
		this.categoryDaoLocal = categoryDaoLocal;
	}
	
	/**
	 * spring
	 * <bean id="calculator" 
        class="org.springframework.jndi.JndiObjectFactoryBean"> 
        <property name="jndiName" value="CalculatorLocal"/> 
        <property name="jndiEnvironment"> 
            <props> 
                <prop key="java.naming.factory.initial"> 
                    org.apache.openejb.client.LocalInitialContextFactory 
                </prop> 
            </props> 
        </property> 
		</bean>
	 */
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse
response)
			throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		
		Context ctx = null;
		Properties jndiEnv = new Properties(); 
		jndiEnv.setProperty("java.naming.factory.initial",
"org.apache.openejb.client.LocalInitialContextFactory"); 

		try {
			ctx = new InitialContext(jndiEnv);
			Object obj = ctx.lookup("CategoryDaoLocal");
			if (obj != null) {
				if (obj instanceof CategoryDaoLocal) {
					this.categoryDaoLocal = (CategoryDaoLocal) obj;
				} else {
					out.println("obj is not instanceof CategoryDaoLocal");
				}
			} else {
				out.println("obj is null");
			}
		} catch (NamingException ex) {
			ex.printStackTrace(out);
		}
		if (this.categoryDaoLocal != null) {
			Category category = new Category();
			category.setCategory("category");
			// currently tomcat exceptions during this call, so lookup works:
			this.categoryDaoLocal.persist(category);
			out.println("<h1>categoryId: " + category.getCategoryId() + "</h1>");
		} else {			
			out.println("<h1>categoryDaoLocal is null</h1>");
		}
	}

But my call to categoryDaoLocal.persist(category) fails with no ending
exceptions like:

http://localhost:8080/HotelWebProject/servlet/TestServletilterChain.java:206)
        at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:233)
        at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:191)
        at
org.apache.openejb.tomcat.catalina.OpenEJBValve.invoke(OpenEJBValve.j
ava:45)
        at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:128)
        at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:102)
        at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
        at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:286)
        at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:845)
        at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ss(Http11Protocol.java:583)
        at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
7)
        at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.IllegalArgumentException: can't parse argument number
        at java.text.MessageFormat.makeFormat(MessageFormat.java:1330)
        at java.text.MessageFormat.applyPattern(MessageFormat.java:450)
        at java.text.MessageFormat.<init>(MessageFormat.java:350)
        at org.apache.openejb.util.Logger$4.compute(Logger.java:108)
        at org.apache.openejb.util.Logger$4.compute(Logger.java:107)
        at org.apache.openejb.util.Memoizer$1.call(Memoizer.java:42)
        at
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:269)
        at java.util.concurrent.FutureTask.run(FutureTask.java:123)
        at org.apache.openejb.util.Memoizer.compute(Memoizer.java:49)
        ... 27 more
java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException:
can
't parse argument number
        at
java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:205)
        at java.util.concurrent.FutureTask.get(FutureTask.java:80)
        at org.apache.openejb.util.Memoizer.compute(Memoizer.java:53)
        at org.apache.openejb.util.Logger.formatMessage(Logger.java:185)
        at org.apache.openejb.util.Logger.debug(Logger.java:234)
        at
org.apache.openejb.core.transaction.JtaTransactionPolicy.beginTransac
tion(JtaTransactionPolicy.java:235)
        at
org.apache.openejb.core.transaction.TxRequired.<init>(TxRequired.java
:54)
        at
org.apache.openejb.core.transaction.JtaTransactionPolicyFactory.creat
eTransactionPolicy(JtaTransactionPolicyFactory.java:36)
        at
org.apache.openejb.core.transaction.EjbTransactionUtil.createTransact
ionPolicy(EjbTransactionUtil.java:55)
        at
org.apache.openejb.core.stateless.StatelessContainer._invoke(Stateles
sContainer.java:200)
        at
org.apache.openejb.core.stateless.StatelessContainer.invoke(Stateless
Container.java:169)
        at
org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbO
bjectProxyHandler.java:217)
        at
org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectPr
oxyHandler.java:77)
        at
org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHa
ndler.java:286)
        at $Proxy67.persist(Unknown Source)
        at
info.toerber.web.servlets.TestServlet.service(TestServlet.java:77)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:290)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
        at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:233)
        at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:191)
        at
org.apache.openejb.tomcat.catalina.OpenEJBValve.invoke(OpenEJBValve.j
ava:45)
        at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:128)
        at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:102)
        at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
        at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:286)
        at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:845)
        at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ss(Http11Protocol.java:583)
        at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
7)
        at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.IllegalArgumentException: can't parse argument number
        at java.text.MessageFormat.makeFormat(MessageFormat.java:1330)
        at java.text.MessageFormat.applyPattern(MessageFormat.java:450)
        at java.text.MessageFormat.<init>(MessageFormat.java:350)
        at org.apache.openejb.util.Logger$4.compute(Logger.java:108)
        at org.apache.openejb.util.Logger$4.compute(Logger.java:107)
        at org.apache.openejb.util.Memoizer$1.call(Memoizer.java:42)
        at
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:269)
        at java.util.concurrent.FutureTask.run(FutureTask.java:123)
        at org.apache.openejb.util.Memoizer.compute(Memoizer.java:49)
        ... 27 more
java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException:
can
't parse argument number
        at
java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:205)
        at java.util.concurrent.FutureTask.get(FutureTask.java:80)
        at org.apache.openejb.util.Memoizer.compute(Memoizer.java:53)
        at org.apache.openejb.util.Logger.formatMessage(Logger.java:185)
        at org.apache.openejb.util.Logger.debug(Logger.java:234)
        at
org.apache.openejb.core.transaction.JtaTransactionPolicy.beginTransac
tion(JtaTransactionPolicy.java:235)
        at
org.apache.openejb.core.transaction.TxRequired.<init>(TxRequired.java
:54)
        at
org.apache.openejb.core.transaction.JtaTransactionPolicyFactory.creat
eTransactionPolicy(JtaTransactionPolicyFactory.java:36)
        at
org.apache.openejb.core.transaction.EjbTransactionUtil.createTransact
ionPolicy(EjbTransactionUtil.java:55)
        at
org.apache.openejb.core.stateless.StatelessContainer._invoke(Stateles
sContainer.java:200)
        at
org.apache.openejb.core.stateless.StatelessContainer.invoke(Stateless
Container.java:169)
        at
org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbO
bjectProxyHandler.java:217)
        at
org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectPr
oxyHandler.java:77)
        at
org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHa
ndler.java:286)
        at $Proxy67.persist(Unknown Source)
        at
info.toerber.web.servlets.TestServlet.service(TestServlet.java:77)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:290)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
        at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:233)
        at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:191)
        at
org.apache.openejb.tomcat.catalina.OpenEJBValve.invoke(OpenEJBValve.j
ava:45)
        at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:128)
        at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:102)
        at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
        at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:286)
        at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:845)
        at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ss(Http11Protocol.java:583)
        at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
7)
        at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.IllegalArgumentException: can't parse argument number
        at java.text.MessageFormat.makeFormat(MessageFormat.java:1330)
        at java.text.MessageFormat.applyPattern(MessageFormat.java:450)
        at java.text.MessageFormat.<init>(MessageFormat.java:350)
        at org.apache.openejb.util.Logger$4.compute(Logger.java:108)
        at org.apache.openejb.util.Logger$4.compute(Logger.java:107)
        at org.apache.openejb.util.Memoizer$1.call(Memoizer.java:42)
        at
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:269)
        at java.util.concurrent.FutureTask.run(FutureTask.java:123)
        at org.apache.openejb.util.Memoizer.compute(Memoizer.java:49)
        ... 27 more
java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException:
can
't parse argument number
        at
java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:205)
        at java.util.concurrent.FutureTask.get(FutureTask.java:80)
        at org.apache.openejb.util.Memoizer.compute(Memoizer.java:53)
        at org.apache.openejb.util.Logger.formatMessage(Logger.java:185)
        at org.apache.openejb.util.Logger.debug(Logger.java:234)
        at
org.apache.openejb.core.transaction.JtaTransactionPolicy.beginTransac
tion(JtaTransactionPolicy.java:235)
        at
org.apache.openejb.core.transaction.TxRequired.<init>(TxRequired.java
:54)
        at
org.apache.openejb.core.transaction.JtaTransactionPolicyFactory.creat
eTransactionPolicy(JtaTransactionPolicyFactory.java:36)
        at
org.apache.openejb.core.transaction.EjbTransactionUtil.createTransact
ionPolicy(EjbTransactionUtil.java:55)
        at
org.apache.openejb.core.stateless.StatelessContainer._invoke(Stateles
sContainer.java:200)
        at
org.apache.openejb.core.stateless.StatelessContainer.invoke(Stateless
Container.java:169)
        at
org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbO
bjectProxyHandler.java:217)
        at
org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectPr
oxyHandler.java:77)
        at
org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHa
ndler.java:286)
        at $Proxy67.persist(Unknown Source)
        at
info.toerber.web.servlets.TestServlet.service(TestServlet.java:77)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:290)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
        at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:233)
        at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:191)
        at
org.apache.openejb.tomcat.catalina.OpenEJBValve.invoke(OpenEJBValve.j
ava:45)
        at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:128)
        at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:102)
        at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
        at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:286)
        at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:845)
        at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ss(Http11Protocol.java:583)
        at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
7)
        at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.IllegalArgumentException: can't parse argument number
        at java.text.MessageFormat.makeFormat(MessageFormat.java:1330)
        at java.text.MessageFormat.applyPattern(MessageFormat.java:450)
        at java.text.MessageFormat.<init>(MessageFormat.java:350)
        at org.apache.openejb.util.Logger$4.compute(Logger.java:108)
        at org.apache.openejb.util.Logger$4.compute(Logger.java:107)
        at org.apache.openejb.util.Memoizer$1.call(Memoizer.java:42)
        at
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:269)
        at java.util.concurrent.FutureTask.run(FutureTask.java:123)
        at org.apache.openejb.util.Memoizer.compute(Memoizer.java:49)
        ... 27 more
java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException:
can
't parse argument number
        at
java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:205)
        at java.util.concurrent.FutureTask.get(FutureTask.java:80)
        at org.apache.openejb.util.Memoizer.compute(Memoizer.java:53)
        at org.apache.openejb.util.Logger.formatMessage(Logger.java:185)
        at org.apache.openejb.util.Logger.debug(Logger.java:234)
        at
org.apache.openejb.core.transaction.JtaTransactionPolicy.beginTransac
tion(JtaTransactionPolicy.java:235)
        at
org.apache.openejb.core.transaction.TxRequired.<init>(TxRequired.java
:54)
        at
org.apache.openejb.core.transaction.JtaTransactionPolicyFactory.creat
eTransactionPolicy(JtaTransactionPolicyFactory.java:36)
        at
org.apache.openejb.core.transaction.EjbTransactionUtil.createTransact
ionPolicy(EjbTransactionUtil.java:55)
        at
org.apache.openejb.core.stateless.StatelessContainer._invoke(Stateles
sContainer.java:200)
        at
org.apache.openejb.core.stateless.StatelessContainer.invoke(Stateless
Container.java:169)
        at
org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbO
bjectProxyHandler.java:217)
        at
org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectPr
oxyHandler.java:77)
        at
org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHa
ndler.java:286)
        at $Proxy67.persist(Unknown Source)
        at
info.toerber.web.servlets.TestServlet.service(TestServlet.java:77)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:290)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
        at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:233)
        at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:191)
        at
org.apache.openejb.tomcat.catalina.OpenEJBValve.invoke(OpenEJBValve.j
ava:45)
        at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:128)
        at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:102)
        at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
        at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:286)
        at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:845)
        at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ss(Http11Protocol.java:583)
        at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
7)
        at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.IllegalArgumentException: can't parse argument number
        at java.text.MessageFormat.makeFormat(MessageFormat.java:1330)
        at java.text.MessageFormat.applyPattern(MessageFormat.java:450)
        at java.text.MessageFormat.<init>(MessageFormat.java:350)
        at org.apache.openejb.util.Logger$4.compute(Logger.java:108)
        at org.apache.openejb.util.Logger$4.compute(Logger.java:107)
        at org.apache.openejb.util.Memoizer$1.call(Memoizer.java:42)
        at
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:269)
        at java.util.concurrent.FutureTask.run(FutureTask.java:123)
        at org.apache.openejb.util.Memoizer.compute(Memoizer.java:49)
        ... 27 more
java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException:
can
't parse argument number
        at
java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:205)
        at java.util.concurrent.FutureTask.get(FutureTask.java:80)
        at org.apache.openejb.util.Memoizer.compute(Memoizer.java:53)
        at org.apache.openejb.util.Logger.formatMessage(Logger.java:185)
        at org.apache.openejb.util.Logger.debug(Logger.java:234)
        at
org.apache.openejb.core.transaction.JtaTransactionPolicy.beginTransac
tion(JtaTransactionPolicy.java:235)
        at
org.apache.openejb.core.transaction.TxRequired.<init>(TxRequired.java
:54)

a) It's only logged to the Console in Tomcat, so had some trouble to get
this log.
b) I tried to change it according to the testing-transactions in the
openejb-examples-1.0. But i got the same Exceptions.

I'll attach my persistence.xml, CategoryDao and CategoryDaoLocal. There is
no WARN, ERROR, ... entry for this in openejb.log. 

I was a little confused what went wrong and therefore looked for a simple
JNDI-Lookup sample to be sure that Injection works. I agree that support is
very good and quick as mentioned there.

Next steps then are:
- Get our application work (MyFaces 1.2, Facelets, Timer, MDBs with
persistent Messages on Tomcat Cluster hopefully with Openejb)
- try to change JPA-Provider to Hibernate (still haven't looked for
automatically database schema update in OpenJPA-Provider)

Our application is currently running on JBoss 4.2.2. @EJB is not currently
working there in Servlet-Engine, but in this context and my collegue is
looking forward to this feature. Currently we are doing this by Spring
JNDI-Factory-Bean.

One of our customers insists on Tomcat and not to use JBoss. So still some
work to do.

In different project we want to save system resources. So would be great to
get this environment working.

Any help appreciated.

Thanks in advance.

Best regards,

JT


David Blevins wrote:
> 
> On Nov 15, 2008, at 7:42 AM, JensToerber wrote:
> 
>> During start of tomcat with openejb ejb-examples-1.0 Web-App  
>> deployed i get
>> the attached openejb.log.
> 
> Looking at your log file it seems you still have the HQSL data sources  
> configured and active in your openejb.xml:
> 
> 2008-11-15 16:30:03,000 - INFO  - Configuring Service(id=My  
> DataSource, type=Resource, provider-id=Default JDBC Database)
> 2008-11-15 16:30:03,000 - INFO  - Configuring Service(id=OracleORCL,  
> type=Resource, provider-id=Default JDBC Database)
> 2008-11-15 16:30:03,000 - INFO  - Configuring  
> Service(id=OracleORCLUnmanaged, type=Resource, provider-id=Default  
> JDBC Database)
> 2008-11-15 16:30:03,000 - INFO  - Configuring Service(id=My Unmanaged  
> DataSource, type=Resource, provider-id=Default JDBC Database)
> 
> If you delete "My DataSource" and "My Unmanaged DataSource" everything  
> will likely just work.  We don't need them for anything and are only  
> there to demonstrate a working setup.
> 
> It should work with them in the openejb.xml, but then you have to  
> either a) move the oracle datasource declarations to the top so we  
> know those are your preferred default datasources, or b) list <jta- 
> data-source>OracleORCL</jta-data-source> and <non-jta-data- 
> source>OracleORCLUnmanaged</non-jta-data-source> in your persistence- 
> unit.
> 
> Really, before reading further I would:
> 
>    1. Replace the openejb 3.0 war with the openejb 3.1 war (better  
> logging, really helps us find issues)
>    2. Delete the unneeded <Resource> declarations from tomcat.base/ 
> conf/openejb.xml
>    3. Make sure your persistence.xml uses the <Resource> declared for  
> <jta-data-source> and <non-jta-data-source> (do *not* use  
> openjpa.ConnectionDriverName)
> 
> That should be good right there.  If that doesn't work, try the  
> example I've included at the bottom.  If that's not clear enough, post  
> your log, openejb.xml, and persistence.xml
> 
> 
>> In Tomcat this is not possible:
>>
>> <persistence-unit transaction-type="JTA" name="jpa-example">
>>    <class>org.superbiz.servlet.JpaBean</class>
>>
>> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</ 
>> provider>
>>        <properties>
>>            <property name="openjpa.jdbc.SynchronizeMappings"
>>                      value="buildSchema"/>
>> 	    <property name="openjpa.ConnectionURL"
>>                       
>> value="jdbc:oracle:thin:@192.168.2.96:1521:orcl"/>
>>
>>            <property name="openjpa.ConnectionDriverName"
>>                      value="oracle.jdbc.OracleDriver"/>
>> 		<!-- don't specify a username/password otherwise:
>> 		java.lang.UnsupportedOperationException: Not supported by  
>> BasicDataSource
>> 	at
>> org 
>> .apache 
>> .commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:902)
>> -->
>>            <property name="openjpa.ConnectionUserName"
>>                      value="openejb"/>
>>
>>            <property name="openjpa.ConnectionPassword"
>>                      value="openejb"/>
>>
>>        </properties>
>>  </persistence-unit>
>>
>> I created my own standalone test application with a BasicDataSource  
>> and i am
>> able to connect to Oracle. Tomcat does not seem to allow this in its  
>> own
>> environment with a username and password.
> 
> Right, and adding connection information other than <jta-data-source>  
> or <non-jta-data-source>OracleORCLUnmanaged</non-jta-data-source> in  
> your persistence-unit declaration is almost guaranteed not to work.   
> I've just created a JIRA
> (https://issues.apache.org/jira/browse/OPENEJB-959 
> ) so we can add some checking to make sure people are not supplying  
> things like "openjpa.ConnectionURL" and equivalent.  Hopefully that  
> will help future users from going off the beaten path.
> 
>> 4.) @PersistenceContext -> persistence.xml -> <tomcat_home>/conf/ 
>> openejb.xml
>> (the simplest solution i guess)
> 
> This is the preferred way.
> 
>> Is there an openejb.xsd for openejb.xml (Tomcat has its  
>> <Resource ... > and
>> Openejb its <Resource ...> but different)?
> 
> Here's a schema: 
> http://svn.apache.org/repos/asf/openejb/tags/openejb-3.0/container/openejb-core/src/main/resources/schema/openejb.xsd
> 
> Though the real information you want is likely here:
> 
> http://openejb.apache.org/3.0/containers-and-resources.html#ContainersandResources-Resources
> 
>> Is it possible to take the
>> org.apache.openjpa.persistence.PersistenceProviderImpl to connect to  
>> Oracle
>> or only to HSQL?
> 
> Any db with a compliant driver will work.
> 
>> I tried to take Hibernate as the JPA-Provider, because i am really  
>> confused
>> right now. Got problems in getting running this because of  
>> incompatible
>> jars, so my problem.
> 
> Right, Hibernate uses an old version of ASM.  This was a real pain for  
> users so in OpenEJB 3.1 we essentially got rid of our dependency on  
> asm so there should be no issue.  But definitely don't do that now, I  
> suspect you'll be looking at a working example in no time.
> 
>> What is really confusing me is the following:
>> <persistence-unit transaction-type="JTA" name="jpa-example">
>>    <jta-data-source>OracleORCL</jta-data-source>
>>    <non-jta-data-source>OracleORCLUnmanaged</non-jta-data-source>
>>    <class>org.superbiz.servlet.JpaBean</class>
>>
>> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</ 
>> provider>
>>    <properties>
>>            <property name="openjpa.jdbc.SynchronizeMappings"
>> value="buildSchema"/>
>>    </properties>
>> </persistence-unit>
>> (Btw. i changed the JpaServlet.java to work with a JTA managed
>> EntityManager)
>>
>> Currently i get a NullPointerException at
>>
>> EntityManager em = emf.createEntityManager();
>>
>> in JpaServlet (see second attached openejb.log).
> 
> That persistence-unit declaration looks spot on and should work given  
> the log output from the first log.  There is no second log, the first  
> one was listed twice, so I'm not sure what may have happened.
> 
>> With
>>    <jta-data-source>jdbc/myoracle</jta-data-source>
>>    <non-jta-data-source>jdbc/myoracle</non-jta-data-source>
>> (configured in <WEB-APP>/META-INF/context.xml:
>> <Resource name="jdbc/myoracle" auth="Container"
>>              type="javax.sql.DataSource"
>> driverClassName="oracle.jdbc.OracleDriver"
>>              url="jdbc:oracle:thin:@192.168.2.96:1521:orcl"
>>              username="openejb" password="openejb" maxActive="20"
>> maxIdle="10"
>>              maxWait="-1"/>)
>> i get a connection to a HSQL-DB?
> 
> This would work if the <Resource> was configured in the tomcat/conf/ 
> server.xml, but we don't yet have support for "webapp" resources being  
> exported (i.e. shared) to OpenEJB. Definitely something we plan to add  
> though.
> 
>> Does openejb take a default datasource (in openejb.xml) if a  
>> configured is
>> not found or wrong or ...?
>> I even tried to change the autoatically generated Datasource- 
>> Resources in
>> <tomcat_home>/conf/openejb.xml to Oracle and still got a HSQL(?).
> 
> So here is the logic we have for selecting a data source for the  
> persistence-unit.  First, if you added connection info via vendor  
> properties in your persistence-unit the persistence provider will  
> likely ignore the datasource we give it and create connections behind  
> our back resulting in nothing working.
> 
> Ideally, things should look like this:
> 
> {openejb.or.tomcat.base}/conf/openejb.xml
>   <Resource id="Orange" type="DataSource">
>     JdbcDriver = org.foo.OrangeDriver
>     JdbcUrl = jdbc:orange:some:stuff
>     JtaManaged = true
>   </Resource>
> 
>   <Resource id="OrangeUnmanaged" type="DataSource">
>     JdbcDriver = org.foo.OrangeDriver
>     JdbcUrl = jdbc:orange:some:stuff
>     JtaManaged = false
>   </Resource>
> 
> {app}/META-INF/persistence.xml
>   <persistence-unit name="orange-unit">
>        <jta-data-source>Orange</jta-data-source>
>        <non-jta-data-source>OrangeUnamanged</non-jta-data-source>
>   </persistence-unit>
> 
> If you don't do exactly that, we will do various things to attempt to  
> figure out how to make things work.  In the 3.1 release the logging  
> for that is a bit better and we won't alter your persistence.xml  
> without telling you exactly what we are setting it to so you can  
> either use those values explicitly or more easily figure out what the  
> right values should look like.
> 
> Here is a test case which shows the steps we'll take to make things  
> work.  At least it shows the input and resulting persistence-unit  
> changes.  Warning I just notices some of the javadoc isn't quite right:
>   
> http://svn.apache.org/repos/asf/openejb/tags/openejb-3.0/container/openejb-core/src/test/java/org/apache/openejb/config/AutoConfigPersistenceUnitsTest.java
> 
>> I guess you know that in the Documentation the Oracle Datasource has  
>> the
>> MySQL Driver and not the Oracle Driver.
> 
> We didn't know, thanks!  I've updated the page.
> 
>> Is there any working sample with an Oracle Datasource, which i could  
>> try?
> 
> I could create one for you but I couldn't legally give it to you with  
> the oracle drivers in it.  Instead, I made you an example setup that  
> uses derby rather than hsqldb.
> 
> All I've done with this binary is:
>   1. Install OpenEJB war into Tomcat and booted Tomcat.
>   2. Edited the auto-created tomcat.base/conf/openejb.xml file
>       2.1.  Set all "JdbcDriver" attributes to  
> "org.apache.derby.jdbc.EmbeddedDriver"
>       2.2.  Set all "JdbcUrl" attributes to  
> "jdbc:derby:sampleDB;create=true"
>       2.3.  Renamed the two <Resource> declarations to make it more  
> obvious in the log file (optional)
>   3. Added derby jars to tomcat.base/lib/
>   4. Restart
> 
> I actually deleted the hsql jars from tomcat.base/webapps/openejb/lib/  
> for good measure, but you don't need to go that far.
> 
> Hope this helps!
> 
> -David
> 
> 
> 
> 
> 
http://www.nabble.com/file/p20637148/persistence.xml persistence.xml 
http://www.nabble.com/file/p20637148/Constants.java Constants.java 
http://www.nabble.com/file/p20637148/CategoryDao.java CategoryDao.java 
http://www.nabble.com/file/p20637148/CategoryDaoLocal.java
CategoryDaoLocal.java  http://www.nabble.com/file/p20637148/DaoAll.java
DaoAll.java  http://www.nabble.com/file/p20637148/openejb.xml openejb.xml 
-- 
View this message in context: http://www.nabble.com/OpenEJB-on-Oracle-tp20294024p20637148.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: OpenEJB on Oracle

Posted by David Blevins <da...@visi.com>.
On Nov 15, 2008, at 7:42 AM, JensToerber wrote:

> During start of tomcat with openejb ejb-examples-1.0 Web-App  
> deployed i get
> the attached openejb.log.

Looking at your log file it seems you still have the HQSL data sources  
configured and active in your openejb.xml:

2008-11-15 16:30:03,000 - INFO  - Configuring Service(id=My  
DataSource, type=Resource, provider-id=Default JDBC Database)
2008-11-15 16:30:03,000 - INFO  - Configuring Service(id=OracleORCL,  
type=Resource, provider-id=Default JDBC Database)
2008-11-15 16:30:03,000 - INFO  - Configuring  
Service(id=OracleORCLUnmanaged, type=Resource, provider-id=Default  
JDBC Database)
2008-11-15 16:30:03,000 - INFO  - Configuring Service(id=My Unmanaged  
DataSource, type=Resource, provider-id=Default JDBC Database)

If you delete "My DataSource" and "My Unmanaged DataSource" everything  
will likely just work.  We don't need them for anything and are only  
there to demonstrate a working setup.

It should work with them in the openejb.xml, but then you have to  
either a) move the oracle datasource declarations to the top so we  
know those are your preferred default datasources, or b) list <jta- 
data-source>OracleORCL</jta-data-source> and <non-jta-data- 
source>OracleORCLUnmanaged</non-jta-data-source> in your persistence- 
unit.

Really, before reading further I would:

   1. Replace the openejb 3.0 war with the openejb 3.1 war (better  
logging, really helps us find issues)
   2. Delete the unneeded <Resource> declarations from tomcat.base/ 
conf/openejb.xml
   3. Make sure your persistence.xml uses the <Resource> declared for  
<jta-data-source> and <non-jta-data-source> (do *not* use  
openjpa.ConnectionDriverName)

That should be good right there.  If that doesn't work, try the  
example I've included at the bottom.  If that's not clear enough, post  
your log, openejb.xml, and persistence.xml


> In Tomcat this is not possible:
>
> <persistence-unit transaction-type="JTA" name="jpa-example">
>    <class>org.superbiz.servlet.JpaBean</class>
>
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</ 
> provider>
>        <properties>
>            <property name="openjpa.jdbc.SynchronizeMappings"
>                      value="buildSchema"/>
> 	    <property name="openjpa.ConnectionURL"
>                       
> value="jdbc:oracle:thin:@192.168.2.96:1521:orcl"/>
>
>            <property name="openjpa.ConnectionDriverName"
>                      value="oracle.jdbc.OracleDriver"/>
> 		<!-- don't specify a username/password otherwise:
> 		java.lang.UnsupportedOperationException: Not supported by  
> BasicDataSource
> 	at
> org 
> .apache 
> .commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:902)
> -->
>            <property name="openjpa.ConnectionUserName"
>                      value="openejb"/>
>
>            <property name="openjpa.ConnectionPassword"
>                      value="openejb"/>
>
>        </properties>
>  </persistence-unit>
>
> I created my own standalone test application with a BasicDataSource  
> and i am
> able to connect to Oracle. Tomcat does not seem to allow this in its  
> own
> environment with a username and password.

Right, and adding connection information other than <jta-data-source>  
or <non-jta-data-source>OracleORCLUnmanaged</non-jta-data-source> in  
your persistence-unit declaration is almost guaranteed not to work.   
I've just created a JIRA (https://issues.apache.org/jira/browse/OPENEJB-959 
) so we can add some checking to make sure people are not supplying  
things like "openjpa.ConnectionURL" and equivalent.  Hopefully that  
will help future users from going off the beaten path.

> 4.) @PersistenceContext -> persistence.xml -> <tomcat_home>/conf/ 
> openejb.xml
> (the simplest solution i guess)

This is the preferred way.

> Is there an openejb.xsd for openejb.xml (Tomcat has its  
> <Resource ... > and
> Openejb its <Resource ...> but different)?

Here's a schema:  http://svn.apache.org/repos/asf/openejb/tags/openejb-3.0/container/openejb-core/src/main/resources/schema/openejb.xsd

Though the real information you want is likely here:

http://openejb.apache.org/3.0/containers-and-resources.html#ContainersandResources-Resources

> Is it possible to take the
> org.apache.openjpa.persistence.PersistenceProviderImpl to connect to  
> Oracle
> or only to HSQL?

Any db with a compliant driver will work.

> I tried to take Hibernate as the JPA-Provider, because i am really  
> confused
> right now. Got problems in getting running this because of  
> incompatible
> jars, so my problem.

Right, Hibernate uses an old version of ASM.  This was a real pain for  
users so in OpenEJB 3.1 we essentially got rid of our dependency on  
asm so there should be no issue.  But definitely don't do that now, I  
suspect you'll be looking at a working example in no time.

> What is really confusing me is the following:
> <persistence-unit transaction-type="JTA" name="jpa-example">
>    <jta-data-source>OracleORCL</jta-data-source>
>    <non-jta-data-source>OracleORCLUnmanaged</non-jta-data-source>
>    <class>org.superbiz.servlet.JpaBean</class>
>
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</ 
> provider>
>    <properties>
>            <property name="openjpa.jdbc.SynchronizeMappings"
> value="buildSchema"/>
>    </properties>
> </persistence-unit>
> (Btw. i changed the JpaServlet.java to work with a JTA managed
> EntityManager)
>
> Currently i get a NullPointerException at
>
> EntityManager em = emf.createEntityManager();
>
> in JpaServlet (see second attached openejb.log).

That persistence-unit declaration looks spot on and should work given  
the log output from the first log.  There is no second log, the first  
one was listed twice, so I'm not sure what may have happened.

> With
>    <jta-data-source>jdbc/myoracle</jta-data-source>
>    <non-jta-data-source>jdbc/myoracle</non-jta-data-source>
> (configured in <WEB-APP>/META-INF/context.xml:
> <Resource name="jdbc/myoracle" auth="Container"
>              type="javax.sql.DataSource"
> driverClassName="oracle.jdbc.OracleDriver"
>              url="jdbc:oracle:thin:@192.168.2.96:1521:orcl"
>              username="openejb" password="openejb" maxActive="20"
> maxIdle="10"
>              maxWait="-1"/>)
> i get a connection to a HSQL-DB?

This would work if the <Resource> was configured in the tomcat/conf/ 
server.xml, but we don't yet have support for "webapp" resources being  
exported (i.e. shared) to OpenEJB. Definitely something we plan to add  
though.

> Does openejb take a default datasource (in openejb.xml) if a  
> configured is
> not found or wrong or ...?
> I even tried to change the autoatically generated Datasource- 
> Resources in
> <tomcat_home>/conf/openejb.xml to Oracle and still got a HSQL(?).

So here is the logic we have for selecting a data source for the  
persistence-unit.  First, if you added connection info via vendor  
properties in your persistence-unit the persistence provider will  
likely ignore the datasource we give it and create connections behind  
our back resulting in nothing working.

Ideally, things should look like this:

{openejb.or.tomcat.base}/conf/openejb.xml
  <Resource id="Orange" type="DataSource">
    JdbcDriver = org.foo.OrangeDriver
    JdbcUrl = jdbc:orange:some:stuff
    JtaManaged = true
  </Resource>

  <Resource id="OrangeUnmanaged" type="DataSource">
    JdbcDriver = org.foo.OrangeDriver
    JdbcUrl = jdbc:orange:some:stuff
    JtaManaged = false
  </Resource>

{app}/META-INF/persistence.xml
  <persistence-unit name="orange-unit">
       <jta-data-source>Orange</jta-data-source>
       <non-jta-data-source>OrangeUnamanged</non-jta-data-source>
  </persistence-unit>

If you don't do exactly that, we will do various things to attempt to  
figure out how to make things work.  In the 3.1 release the logging  
for that is a bit better and we won't alter your persistence.xml  
without telling you exactly what we are setting it to so you can  
either use those values explicitly or more easily figure out what the  
right values should look like.

Here is a test case which shows the steps we'll take to make things  
work.  At least it shows the input and resulting persistence-unit  
changes.  Warning I just notices some of the javadoc isn't quite right:
   http://svn.apache.org/repos/asf/openejb/tags/openejb-3.0/container/openejb-core/src/test/java/org/apache/openejb/config/AutoConfigPersistenceUnitsTest.java

> I guess you know that in the Documentation the Oracle Datasource has  
> the
> MySQL Driver and not the Oracle Driver.

We didn't know, thanks!  I've updated the page.

> Is there any working sample with an Oracle Datasource, which i could  
> try?

I could create one for you but I couldn't legally give it to you with  
the oracle drivers in it.  Instead, I made you an example setup that  
uses derby rather than hsqldb.

All I've done with this binary is:
  1. Install OpenEJB war into Tomcat and booted Tomcat.
  2. Edited the auto-created tomcat.base/conf/openejb.xml file
      2.1.  Set all "JdbcDriver" attributes to  
"org.apache.derby.jdbc.EmbeddedDriver"
      2.2.  Set all "JdbcUrl" attributes to  
"jdbc:derby:sampleDB;create=true"
      2.3.  Renamed the two <Resource> declarations to make it more  
obvious in the log file (optional)
  3. Added derby jars to tomcat.base/lib/
  4. Restart

I actually deleted the hsql jars from tomcat.base/webapps/openejb/lib/  
for good measure, but you don't need to go that far.

Hope this helps!

-David




Re: OpenEJB on Oracle

Posted by JensToerber <je...@juwimm.com>.
Hi again,

i tried today several steps, but still could not find the error.
Still i am only connecting to HSQL.

At the moment i am trying to get the examples-1.0-Web-Application running on
Tomcat 6.0.18 on Oracle, not my own application.

I turned on logging in 
<tomcat_home>/conf/logging.properties:
log4j.category.OpenEJB             = DEBUG,R
log4j.category.OpenEJB.server      = DEBUG
log4j.category.OpenEJB.startup     = DEBUG
log4j.category.OpenEJB.startup.service = DEBUG
log4j.category.OpenEJB.startup.config = DEBUG
log4j.category.OpenEJB.hsql        = DEBUG
log4j.category.OpenEJB.ws          = DEBUG
log4j.category.CORBA-Adapter       = DEBUG,R
log4j.category.Transaction         = DEBUG,TX
log4j.category.org.apache.activemq = DEBUG,R
log4j.category.org.apache.geronimo = DEBUG,R
log4j.category.openjpa             = DEBUG,R
log4j.category.axis                 = DEBUG,R
log4j.category.axis2                 = DEBUG,R
log4j.category.cxf                 = DEBUG,R

During start of tomcat with openejb ejb-examples-1.0 Web-App deployed i get
the attached openejb.log.

In Tomcat this is not possible:

<persistence-unit transaction-type="JTA" name="jpa-example">
    <class>org.superbiz.servlet.JpaBean</class>
   
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> 
        <properties> 
            <property name="openjpa.jdbc.SynchronizeMappings" 
                      value="buildSchema"/> 
	    <property name="openjpa.ConnectionURL" 
                      value="jdbc:oracle:thin:@192.168.2.96:1521:orcl"/> 

            <property name="openjpa.ConnectionDriverName" 
                      value="oracle.jdbc.OracleDriver"/> 
		<!-- don't specify a username/password otherwise:
		java.lang.UnsupportedOperationException: Not supported by BasicDataSource
	at
org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:902)
-->
            <property name="openjpa.ConnectionUserName" 
                      value="openejb"/> 

            <property name="openjpa.ConnectionPassword" 
                      value="openejb"/> 
                      
        </properties> 
  </persistence-unit>

I created my own standalone test application with a BasicDataSource and i am
able to connect to Oracle. Tomcat does not seem to allow this in its own
environment with a username and password.

Usually we are working on JBoss 4.x.x. There we configure a Datasource where
we point to directly or better via web.xml -> jboss-web.xml ->
JNDI-Datasource configured by a *-ds.xml.

What is the preferred way here?
1.) @PersistenceContext -> persistence.xml -> web.xml ->
webapp/META-INF/context.xml (possible? if yes how?)
2.) @PersistenceContext -> persistence.xml -> <webapp>/META-INF/context.xml
?
3.) @PersistenceContext -> persistence.xml -> web.xml ->
<tomcat_home>/conf/openejb.xml (how?)
4.) @PersistenceContext -> persistence.xml -> <tomcat_home>/conf/openejb.xml
(the simplest solution i guess)

Is there an openejb.xsd for openejb.xml (Tomcat has its <Resource ... > and
Openejb its <Resource ...> but different)?

Is it possible to take the
org.apache.openjpa.persistence.PersistenceProviderImpl to connect to Oracle
or only to HSQL?

I tried to take Hibernate as the JPA-Provider, because i am really confused
right now. Got problems in getting running this because of incompatible
jars, so my problem.

What is really confusing me is the following:
<persistence-unit transaction-type="JTA" name="jpa-example">
    <jta-data-source>OracleORCL</jta-data-source>
    <non-jta-data-source>OracleORCLUnmanaged</non-jta-data-source>
    <class>org.superbiz.servlet.JpaBean</class>
   
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    <properties> 
            <property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema"/> 
    </properties>
</persistence-unit>
(Btw. i changed the JpaServlet.java to work with a JTA managed
EntityManager)

Currently i get a NullPointerException at

EntityManager em = emf.createEntityManager();

in JpaServlet (see second attached openejb.log).

With
    <jta-data-source>jdbc/myoracle</jta-data-source>
    <non-jta-data-source>jdbc/myoracle</non-jta-data-source>
(configured in <WEB-APP>/META-INF/context.xml:
<Resource name="jdbc/myoracle" auth="Container"
              type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
              url="jdbc:oracle:thin:@192.168.2.96:1521:orcl"
              username="openejb" password="openejb" maxActive="20"
maxIdle="10"
              maxWait="-1"/>)
i get a connection to a HSQL-DB?

Does openejb take a default datasource (in openejb.xml) if a configured is
not found or wrong or ...?
I even tried to change the autoatically generated Datasource-Resources in
<tomcat_home>/conf/openejb.xml to Oracle and still got a HSQL(?).

I guess you know that in the Documentation the Oracle Datasource has the
MySQL Driver and not the Oracle Driver.

Is there any working sample with an Oracle Datasource, which i could try?

Any help welcome.

Best regards,

JT 

JensToerber wrote:
> 
> Hi altogether,
> 
> i am using OpenEJB 3.x as standalone edition for JUnit tests and i tried
> to get OpenEJB Examples running on Tomcat 6.0.x. on Oracle 10g.
> 
> I have problems configuring the persistence units and/or datasources. I am
> not quite sure what the problem is:
> 
> persistence.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> <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">
> 	<!--
> 	only one persistence unit per project by JPA Tools supported
> 	-->
> 	<!--
> 	<persistence-unit name="JPATestProject">
> 	</persistence-unit>
> 	-->
> 	<persistence-unit name="beds_pu" transaction-type="JTA">
> 		<provider>org.hibernate.ejb.HibernatePersistence</provider>
> 		<jta-data-source>OracleORCL</jta-data-source>
> 		<non-jta-data-source>OracleORCLUnmanaged</non-jta-data-source> 
>         <class>info.toerber.beds.model.Test</class>
> 	</persistence-unit>
> </persistence>
> 
> in one of my session beans i am declaring a datasource like:
> @Resource(name="OracleORCL")
>     DataSource dataSource;
> 
> In standalone for JUnit-Test it seems to be that OpenEJB always takes its
> default Database HSQL.
> Is this correct?
> Is it possible to change this to an Oracle Datasource?
> 
> here is my openejb.xml in META-INF for standalone and in <tomcat>/conf for
> Tomcat deployment:
> <openejb>
> 	<Resource id="OracleORCL" type="DataSource">
>     #  Oracle example
>     #
>     #  This connector will not work until you download the driver at:
>     #  http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html
>     JdbcDriver  oracle.jdbc.OracleDriver
>     JdbcUrl     jdbc:oracle:thin:@192.168.2.96:1521:ORCL
>     UserName    openejb
>     Password    openejb
> 	JtaManaged true
> </Resource>
> <Resource id="OracleORCLUnmanaged" type="DataSource">
>     #  Oracle example
>     #
>     #  This connector will not work until you download the driver at:
>     #  http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html
>     JdbcDriver  oracle.jdbc.OracleDriver
>     JdbcUrl     jdbc:oracle:thin:@192.168.2.96:1521:ORCL
>     UserName    openejb
>     Password    openejb
> 	JtaManaged  false
> </Resource>
> </openejb>
> 
> The examples are running in Tomcat, but always on HSQL as i can see with
> 
> if (this.entityManager != null) {
> 				Object delegate = this.entityManager.getDelegate();
> 				if (delegate instanceof HibernateEntityManager) {
> 						HibernateEntityManager hibernateEntityManager =
> (HibernateEntityManager) delegate;
> 						Session s = hibernateEntityManager.getSession();
> 						Connection conn = s.connection();
> 						inspectConnection(conn);
> 
> private void inspectConnection(Connection conn) throws SQLException {
> 		DatabaseMetaData dataBaseMetaData = conn.getMetaData();
> 		// The drivers are included with OpenEJB 3.0 and HSQLDB is the default
> database.
> 		System.out.println(dataBaseMetaData.getDatabaseMajorVersion());
> 		System.out.println(dataBaseMetaData.getDatabaseMinorVersion());
> 		System.out.println(dataBaseMetaData.getDatabaseProductName());
> 		System.out.println(dataBaseMetaData.getDatabaseProductVersion());
> 		System.out.println(dataBaseMetaData.getDefaultTransactionIsolation());
> 		System.out.println(dataBaseMetaData.getDriverMajorVersion());
> 		System.out.println(dataBaseMetaData.getDriverMinorVersion());
> 		System.out.println(dataBaseMetaData.getDriverName());
> 		System.out.println(dataBaseMetaData.getDriverVersion());
> 
> I could change the default Persistence Provider, but it's not running on
> my Oracle Datasource.
> Looked in the documentation and i can see that HSQL is the default
> database. But how and where can i change it always or for a specific
> persistence unit or for a resource in standalone and/or Tomcat?
> 
> Btw. the persistence unit works if i take this in Eclipse JPA Tools:
> persistence.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> <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">
> 	<!--
> 	only one persistence unit per project by JPA Tools supported
> 	-->
> 	<!--
> 	<persistence-unit name="JPATestProject">
> 	</persistence-unit>
> 	-->
> 	<persistence-unit name="beds_pu" transaction-type="RESOURCE_LOCAL">
>       <provider>org.hibernate.ejb.HibernatePersistence</provider>
>       <!-- use persistence.xml right mouse Synchronize classes to get
> actual list -->
>       <class>info.toerber.beds.model.Test</class>
>       <properties>
>          <property name="hibernate.dialect"
> value="org.hibernate.dialect.Oracle10gDialect"/>
>          <property name="hibernate.connection.driver_class"
> value="oracle.jdbc.OracleDriver"/>
>          <property name="hibernate.connection.username" value="openejb"/>
>          <property name="hibernate.connection.password" value="openejb"/>
>          <property name="hibernate.connection.url"
> value="jdbc:oracle:thin:@192.168.2.96:1521:ORCL"/>
>          <property name="hibernate.max_fetch_depth" value="3"/>
>          <!-- JPA Tools looks for this setting(?), so does not always drop
> the table as announced -->
>          <property name="hibernate.hbm2ddl.auto" value="update" />
>        	 <!--
>          creates table at start and drops at the end!!
>          <property name="hibernate.hbm2ddl.auto" value="create-drop" />
>        	 -->
>          <!-- cache configuration
>          <property
> name="hibernate.ejb.classcache.org.hibernate.ejb.test.Item"
> value="read-write"/>
>          <property
> name="hibernate.ejb.collectioncache.org.hibernate.ejb.test.Item.distributors"
> value="read-write, RegionName"/>
>          -->
> 
>          <!-- alternatively to <class> and <property> declarations, you
> can use a regular hibernate.cfg.xml file -->
>          <!-- property name="hibernate.ejb.cfgfile"
> value="/org/hibernate/ejb/test/hibernate.cfg.xml"/ -->
>       </properties>
>    </persistence-unit>
> </persistence>
> 
> Any help welcome.
> Thanks in advance.
> 
> Jens Toerber
> 
http://www.nabble.com/file/p20516594/openejb.log openejb.log 
http://www.nabble.com/file/p20516594/openejb.log openejb.log 
-- 
View this message in context: http://www.nabble.com/OpenEJB-on-Oracle-tp20294024p20516594.html
Sent from the OpenEJB User mailing list archive at Nabble.com.