Apache Tomcat (TomEE)/8.5.6 (7.0.2) Oracle JTS/XA-Datasource Configuration - oracle

Has anybody a running example configuration for:
Apache Tomcat (TomEE)/8.5.6 (7.0.2) PLUME
Oracle 11g (ojdbc7.jar)
to match EE/JPA 2.1-Development as near as possible?
Currently i get TomEE's user database, if i try to use my datasource. I think it's caused by the log entry "org.apache.openejb.config.AutoConfig.deploy Found matching datasource: jdbc/jKgvDS but this one is not a JTA datasource", falling back to the last known running datasource. So how can i configure a valid JTA datasource?
server.xml:
<Resource id="jKgvDS" name="jdbc/jKgvDS"
jtaManaged="true"
auth="Container"
type="oracle.jdbc.xa.client.OracleXADataSource"
driverClassName="oracle.jdbc.xa.client.OracleXADataSource"
factory="oracle.jdbc.pool.OracleDataSourceFactory"
url="jdbc:oracle:thin:#db:1521:db"
username="myuser"
password="mypass"
maxActive="20"
maxIdle="30"
maxWait="-1"
validationQuery="SELECT 1 FROM DUAL"
/>
context.xml (tried in conf and app-file)
<ResourceLink global='jdbc/jKgvDS'
name='jdbc/jKgvDS' type="javax.sql.XADatasource"
auth="Container" />
persistence.xml
<persistence-unit name="jKgvPU" transaction-type="JTA">
<jta-data-source>jdbc/jKgvDS</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<validation-mode>NONE</validation-mode>
<properties>
<property
name="openjpa.jdbc.DBDictionary"
value="org.apache.openjpa.jdbc.sql.OracleDictionary" />
<property
name="openjpa.jdbc.DBDictionary"
value="oracle(maxEmbeddedBlobSize=-1,maxEmbeddedClobSize=-1)" />
<property
name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)" />
</properties>
</persistence-unit>

Here we go (yeah...):
<Resource id="jKgvDS" name="jdbc/jKgvDS"
jtaManaged="true"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
url="jdbc:oracle:thin:#POSDBORA:1521:posdbora"
username="myuser"
password="mypass"
maxActive="20"
maxIdle="30"
maxWait="-1"
validationQuery="SELECT 1 FROM DUAL"
/>
References in web.xml or context.xml are not needed to run.

Related

Defining a datasource resource in tomcat context.xml

I'm using Spring batch and spring batch admin and i write in applicationContext this code, defining a bean called dataSource:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" ... />
Now, i would change this code, defining my "dataSource" in the context.xml file of Tomcat and then load it.
I read that this is possible defining a Resource like this:
<Resource auth="Container" driverClassName="oracle.jdbc.driver.OracleDriver"
maxActive="100" maxIdle="30" maxWait="10000" name="jdbc/myDatabase"
password="myPass" type="javax.sql.DataSource"
url="jdbc:oracle:thin:#host.com:1521/abc" username="myUser" />
and then loading it in my applicationContext.xml using this:
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/myDatabase" />
But with this i have a problem. It is possible to define a resource for my dataSource so that it is of class org.apache.commons.dbcp.BasicDataSource and not javax.sql.DataSource?
Any help?
Thank you

Tomcat Connection Pool's attribute setting

My web application connect DB by Tomcat jdbc pool.
this is my Tomcat context.xml
<Resource
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
name="jdbc/OracleDB"
auth="Container"
type="javax.sql.DataSource"
initialSize="70"
maxActive="100"
maxIdle="30"
minIdle="10"
maxWait="5000"
removeAbandoned="true"
removeAbandonedTimeout="60"
username="XXOO"
password="XXOO"
driverClassName="oracle.jdbc.driver.OracleDriver"
validationQuery="SELECT 'OK'"
testWhileIdle="true"
testOnBorrow="true"
numTestsPerEvictionRun="5"
timeBetweenEvictionRunsMillis="30000"
minEvictableIdleTimeMillis="60000"
url="jdbc:oracle:thin:#XXOO:testdb"/>
connection timeout will be happened 1min50sec
If I use JDBC to connect DB,it would not happen.
So what's setting do I lose or modify?

AssertionFailure: Transaction MARKED_FOR_JOINED after isOpen() call

While deploying in tomcat 8 server, I got following error
AssertionFailure: Transaction MARKED_FOR_JOINED after isOpen() call
Following are the details of the configuration.
Server: tomcat 8
Hibernate 3
Spring 3
Context.xml of server..
I have done database setting:
<Resource name="jdbc/meerkatDataSource"
auth="Container"
type="javax.sql.DataSource"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:#10.237.59.104:1521:MEERKAT"
username="meerkat"
password="meerkat"
maxActive="100"
maxIdle="20"
minIdle="5"
maxWait="10000"/>
<Resource name="UserTransaction" auth="Container" type="javax.transaction.UserTransaction"
factory = "org.objectweb.jotm.UserTransactionFactory"/>
<Transaction factory="org.objectweb.jotm.UserTransactionFactory" jotm.timeout="60"/>
<Resource
name="TransactionSynchronizationRegistry"
auth="Container"
type="javax.transaction.TransactionSynchronizationRegistry"
factory="org.objectweb.jotm.TransactionSynchronizationRegistryFactory"/>
Transaction.xml -->
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="userTransactionName" value="java:comp/UserTransaction">
<property name="transactionSynchronizationRegistryName" value="java:comp/env/TransactionSynchronizationRegistry"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
Persistent.xml-->
<persistence-unit name="meerkatPersistenceUnit" transaction-type="JTA">
<jta-data-source>jdbc/meerkatDataSource</jta-data-source>
Please suggest if any changes to be done. Also note that, database setting is strictly under tomcat server.
As per my understanding ,
here you are using data source type="javax.sql.DataSource" using the factory : "org.apache.tomcat.jdbc.pool.DataSourceFactory"
and the transaction manager is jta type :
class="org.springframework.transaction.jta.JtaTransactionManager">
It can be solved if it the data bas is replaced by having the type
javax.sql.XADataSource in turn using the class :
an org.enhydra.jdbc.pool.StandardXAPoolDataSource. Make sure the prsistence manager uses the same datasource.
For further info go through :
https://tomcat.apache.org/tomcat-8.0-doc/jdbc-pool.html
http://xapool.ow2.org/doc/api/jdoc-1.3/org/enhydra/jdbc/pool/StandardXAPoolDataSource.html

spring example with wrong datasource configuration

I try to run the example project of jboss-springmvc-webapp, but I fail to configure the data source.
the error is:
JBAS014775: New missing/unsatisfied dependencies:
service jboss.jdbc-driver.mysql (missing) dependents: [service jboss.data-source.jboss/datasources/SpringQuickstartDS]
my persistence.xml is:
<persistence version="2.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_2_0.xsd">
<persistence-unit name="primary">
<!-- If you are running in a production environment, add a managed
data source, this example data source is just for development and testing! -->
<!-- The datasource is deployed as WEB-INF/spring-quickstart-ds.xml, you
can find it in the source at src/main/webapp/WEB-INF/spring-quickstart-ds.xml -->
<jta-data-source>java:jboss/datasources/SpringQuickstartDS</jta-data-source>
<properties>
<property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/spring-quickstart/persistence" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.show_sql" value="false" />
</properties>
</persistence-unit>
</persistence>
my datasource.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<datasources xmlns="http://www.jboss.org/ironjacamar/schema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
<!-- The datasource is bound into JNDI at this location. We reference
this in META-INF/persistence.xml -->
<datasource jndi-name="java:jboss/datasources/SpringQuickstartDS"
pool-name="kitchensink-quickstart" enabled="true"
use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/testdb</connection-url>
<driver>mysql</driver>
<security>
<user-name>root</user-name>
<password></password>
</security>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="mysql" module="com.mysql.jdbc">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
<driver name="postgresql" module="org.postgresql.jdbc">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
If you use the jboss-springmvc-webapp architype then it should come configured to use H2 as a datasource. I would go back to that configuration first to confirm that it works.
Then when you know everything else is working you can set up a MySQL datasource. There are 2 things you need to know. You can only point to one datasource at a time, so you must remove the other ones from the file above. It can only have the MySQL info (if that is the datasource you are using). Second, you will need to make sure you have the JDBC driver for the database that you are going to use.
Every version of JBoss has good docs on setting this up. What version of JBoss are you using, I'll post the doc page?

How to change Spring to use Datasource from Tomcat vs BasicDataSource?

How to change Spring to use Datasource from Tomcat vs BasicDataSource? below is a copy of the bean I make in my XML. Can someone tell me how to access the tomcat datasource
<beans:bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" >
<beans:property
name="driverClassName"
value="${database.driver}" />
<beans:property
name="url"
value="${database.url}" />
<beans:property
name="username"
value="${database.user}" />
<beans:property
name="password"
value="${database.password}" />
<beans:property
name="initialSize"
value="5" />
<beans:property
name="maxActive"
value="10" />
</beans:bean>
In spring you have to change the configuration that it takes the configuration from tomcat via JNDI
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/myNewDatasource" />
</beans>
Then you have to configure the connection within tomact and make it available though jndi.
For example you could put this in the tomcat context.xml (and of course you need to put the driver in the tomcat lib directory)
<Resource name="jdbc/myNewDatasource"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://SERVER:3306/DB?useUnicode=true&characterEncoding=utf8"
auth="Container" username="USERNAME" password="PASSWORD"
maxIdle="3" maxActive="15" maxWait="10000"
logAbandoned="true" removeAbandoned="true" removeAbandonedTimeout="60"
validationQuery="select 1" />

Resources