openejb-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From JensToerber <jens.toer...@juwimm.com>
Subject Re: OpenEJB on Oracle
Date Sat, 15 Nov 2008 15:42:44 GMT

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.


Mime
View raw message