I am upgrading from JBoss AS 4.0.4.GA to JBoss 6.0.0.Final.
I have been unable to lookup a HornetQ Topic from an external Java client, so I decided to write a little test Java program that did a simple lookup of a DataSource. That lookup is failing. I can see the DataSource in the web console and it has:
Pool JNDI Name = MyDS
I used to (with JBoss 4.0.4.GA) lookup the DataSource using "java:/MyDS", but that is not working. I have seen some talk about not being able to lookup objects (Queues,Topics,DataSources,EJBs,etc) from outside the AS. I'd be surprised if that is the case, but if it is, then how do I disable that "feature"?
The DS is in server/myconf/deploy/mysql-ds.xml:
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>MyDS</jndi-name>
<connection-url>jdbc:mysql://localhost:3306/mydb</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>xxxxxxxx</user-name>
<password>xxxxxxxx</password>
<prepared-statement-cache-size>50</prepared-statement-cache-size>
<min-pool-size>20</min-pool-size>
<max-pool-size>40</max-pool-size>
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
The Java program that looks up the DS is:
env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(javax.naming.Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
env.put(javax.naming.Context.PROVIDER_URL, "jnp://localhost:1099");
InitialContext ctx = new InitialContext(env);
Object o = ctx.lookup("java:/MyDS");
The lookup line throws a NameNotFoundException:
javax.naming.NameNotFoundException: MyDS not bound
I've tried the lookup with just "MyDS" rather than "java:/MyDS", but it still fails. I don't think the problem is the name I'm using to lookup, rather something preventing me doing any lookup from an external application - and if that is the case, I need to enable such lookups.
Update the datasource definition like:
<use-java-context>false</use-java-context>
e.g.
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>MyDS</jndi-name>
<use-java-context>false</use-java-context>
<connection-url>jdbc:mysql://localhost:3306/mydb</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>xxxxxxxx</user-name>
<password>xxxxxxxx</password>
<prepared-statement-cache-size>50</prepared-statement-cache-size>
<min-pool-size>20</min-pool-size>
<max-pool-size>40</max-pool-size>
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
Related
I am using WebSphere Liberty 17.0.0.2.
The end product is an ear that contains a jar which is using JPA to access database.
The EntityManager is annotated with #PersistenceContext with persistence unit name defined. In the persistence.xml under appropriate persistence-unit the jta-data-source tag contains datasource name (direct lookup) specified in server.xml. With this setup everything is working fine.
Now need arose that I need to switch from direct lookup to indirect lookup regarding datasource JNDI lookup method. As I understand indirect lookup is something like OS environment variables. I use a name to get the configured value, so I can switch datasources without touching my code to rename JDNI names there.
Switching from direct to indirect I'd need to append 'java:comp/env' in my persistence.xml for the jta-data-source.
How can I connect datasource name with indirect lookup name? I tried to specify it in server.xml using resource-ref tag but with no luck.
The main goal here is to using indirect lookup in the code but be able to change datasources in the applicaton server configuration, so I don't have to change my application when this is happning.
Configuration snippets:
server.xml
<library id="oraclelib">
<jdbcDriver id="oracledriver" libraryRef="oraclelib">
<dataSource jndiName="jdbc/oradb" jdbcDriverRef="oracledriver" id="oradbds">
<resource-ref name="jdbc/oradb" binding-name="jdbc/mydb">
persistence.xml
<jta-data-source>java:comp/env/jdbc/mydb</jta-data-source>
When running this setup a javax.naming.NameNotFoundException is thrown.
Update #1
server.xml after swapping name, binding-name
<?xml version="1.0" encoding="UTF-8"?>
<server description="app server">
<library id="OracleLib">
<fileset dir="/oracle" includes="ojdbc6.jar" />
</library>
<jdbcDriver id="OracleJDBCDriver" libraryRef="OracleLib" />
<dataSource jndiName="jdbc/oradb" jdbcDriverRef="OracleJDBCDriver" id="dbDataSource">
<properties.oracle URL="jdbc:oracle:thin:#//dbhost:port/SID" user="dbuser" password="dbpassword" />
</dataSource>
<application id="Myapp_ear" location="/path/myapp.ear" name="Myapp_ear" type="ear">
<application-bnd>
<resource-ref name="jdbc/mydb" binding-name="jdbc/oradb" />
</application-bnd>
</application>
</server>
jta-data-source is java:comp/env/jdbc/mydb
Solution
It turned out that the bean that was used to get EntityManager was a CDI bean. As it is modified to be an EJB bean, the ejb-jar.xml, ibm-ejb-jar-bnd.xml did the trick.
It should be the other way around:
not
<resource-ref name="jdbc/oradb" binding-name="jdbc/mydb">
but
<resource-ref name="jdbc/mydb" binding-name="jdbc/oradb">
name - is resource ref name, and binding-name is jndi name in the server configuration.
My question is: How do I map a datasource to a specific jndi-name configured inside wildfly so that multiple deployed .war-files each can use their own specific datasource. The mapping should take place at deployment so that a configuration inside wildfly and the specific project is sufficient.
We got a project which supports multi-tenancy. The structure is as follows:
customerSpecificProject
|-- ui (generic)
|----database (generic)
|----services (generic)
|----etc...
In the database-project a standard datasource is specified which goes by a standard jndi-name java:/xyzDS. Since we migrated from tomcat to wildfly we want to make use of the ability to host multiple applications in our AS.
To achieve this we have to map the java:/xyzDS to the datasources defined in the standalone.xml:
<subsystem xmlns="urn:jboss:domain:datasources:4.0">
<datasources>
<datasource jta="true" jndi-name="java:/customer1DS" pool-name="c1DS" enabled="true" use-ccm="true">
...
</datasource>
<datasource jta="true" jndi-name="java:/customer2DS" pool-name="c2DS" enabled="true" use-ccm="true">
...
</datasource>
Therefore we tried to use the jboss-web.xml located in the WEB-INF folder of our customerProject:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.jboss.com/xml/ns/javaee
http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
<resource-ref>
<res-ref-name>java:/xyzDS</res-ref-name>
<jndi-name>java:/customer1DS</jndi-name>
</resource-ref>
</jboss-web>
persistence.xml inside the database-Project:
<?xml version='1.0' encoding='UTF-8'?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/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_1.xsd">
<persistence-unit name="xyzDB" transaction-type="JTA">
<jta-data-source>java:/xyzDS</jta-data-source>
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>...</class>
...
<class>...</class>
<shared-cache-mode>NONE</shared-cache-mode>
<validation-mode>NONE</validation-mode>
<properties>
<property name="eclipselink.weaving" value="static" />
</properties>
</persistence-unit>
</persistence>
It does not seem to be working. I talked to a colleague who had a similar issue and resolved it in the corresponding way for a websphere AS. I do not know if the problem resides in the structure having a nested databaseProject inside another lib (ui) for the actual customerProject or if it is caused by bad configuration.
Also we use the #Resource Annotation inside some DAOs:
#Resource(lookup = "java:/xyzDS")
private DataSource dataSource;
Maybe the mapping works but not for the annotations inside the compiled DAOs? But I do not understand why that should not work.
Current Error in Stacktrace:
11:18:20,839 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 1) WFLYCTL0013: Operation ("full-replace-deployment") failed - address: ([]) - failure description: {
"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"xyz.war\".INSTALL" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"xyz.war\".INSTALL: WFLYSRV0153: Failed to process phase INSTALL of deployment \"xyz.war\"
Caused by: java.lang.IllegalArgumentException: WFLYEE0047: Incompatible conflicting binding at java:/xyzDS source: lookup (java:/customer1DS)"},
Edit: Already tried adding:
<property name="wildfly.jpa.twophasebootstrap" value="false"/>
To persistence.xml
Have you checked the question/answer in wildfly-development.1055759.n5.nabble.com? In this exchange, it was determined that the persistence unit needed a hint in the form of
<property name="wildfly.jpa.twophasebootstrap" value="false"/>
I don't know if this is applicable in your case, but is worth looking at.
I am unable to configure datasource in jBoss. Following is configuration in jboss web.xml
<jboss-web>
<resource-ref>
<res-ref-name>jdbc/testDataSource</res-ref-name> <!-- matches web.xml -->
<jndi-name>java:jdbc/testDataSource</jndi-name> <!-- matches oracle-ds.xml -->
<res-type>javax.sql.DataSource</res-type>
</resource-ref>
</jboss-web>
We have created oracle-ds.xml which contains:
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>jdbc/testDataSource</jndi-name>
<connection-url>jdbc:oracle:thin:#11.120.184.77:1521:starsdev</connection-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>cmsusr</user-name>
<password>cmsusr</password>
<min-pool-size>2</min-pool-size>
<max-pool-size>20</max-pool-size>
<idle-timeout-minutes>5</idle-timeout-minutes>
<track-statements/>
<metadata>
<type-mapping>Oracle10g</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
I have created one servlet which contains following code in service method:
Context initialContext = new InitialContext();
Context envContext = (Context) initialContext.lookup( "java:comp/env" );
DataSource ds = (DataSource) envContext.lookup( "jdbc/testDataSource" );
PrintWriter pw = response.getWriter();
pw.print(ds);
When I'm running my servlet it is showing following error:
[STDOUT] javax.naming.NameNotFoundException: jdbc not bound
Do it in a single lookup. There's no need to use two Contexts here.
Context initialContext = new InitialContext();
DataSource ds = (DataSource) initialContext.lookup("java:comp/env/jdbc/testDataSource");
I have JBoss 4 with 2 Oracle datasources: CurrentDS and ArchiveDS.
But hibernate uses only scheme for CurrentDS when creates tables from annotations, and scheme for ArchiveDS stays empty. My opinion - when he starts creating tables for Archive he finds just created tables in CurrentDS and thinks that they already exist (using wrong credentials).
This works OK on Postgres, what could it be about on Oracle?
<datasources>
<local-tx-datasource>
<jndi-name>CurrentDS</jndi-name>
<connection-url>jdbc:oracle:thin:#localhost:1521:XE</connection-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>current</user-name>
<password>password</password>
<metadata>
<type-mapping>Oracle9i</type-mapping>
</metadata>
</local-tx-datasource>
<local-tx-datasource>
<jndi-name>ArchiveDS</jndi-name>
<connection-url>jdbc:oracle:thin:#localhost:1521:XE</connection-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>archive</user-name>
<password>password</password>
<metadata>
<type-mapping>Oracle9i</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
We are using Jboss 4.2.3 with EJBs and hibernate.
Currently we defined 3 db connections in our persistence.xml file (one for reads (tx-local), one for writes (no-tx) and one for statistics (no-tx)), and when we add a forth db connection which is also (no-tx) and map a couple of entities to it, the machine starts to show an unusual load.
If we remove this connection (no one is using it still) the load get back to normal.
I guess it is some sort of configuration problem with JBoss, but I'm not sure.
any assistance will be appreciated.
thanks.
this is the ds.xml file content:
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: feedback-ds.xml 71535 2008-04-01 07:05:03Z adrian#jboss.org $ -->
<!-- Datasource config for MySQL using 3.0.9 available from:
http://www.mysql.com/downloads/api-jdbc-stable.html
-->
<datasources>
<no-tx-datasource>
<jndi-name>FeedbackDS</jndi-name>
<connection-url>jdbc:mysql://m6sdb:3306/m6sFeedbacks?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>root</user-name>
<password>password</password>
<min-pool-size>10</min-pool-size>
<!-- The maximum connections in a pool/sub-pool -->
<max-pool-size>1000</max-pool-size>
<property name="hibernate.show.sql" value="true"></property>
<idle-timeout-minutes>10</idle-timeout-minutes>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
<!-- should only be used on drivers after 3.22.1 with "ping" support -->
<valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</no-tx-datasource>
</datasources>