What to put into jta-data-source of persistence.xml that works on all vendors?


Similar to <a href="https://stackoverflow.com/questions/4051273/what-to-put-into-jta-data-source-of-persistence-xml" rel="nofollow">What to put into jta-data-source of persistence.xml?</a> and <a href="https://stackoverflow.com/questions/42434282/how-to-map-jpa-datasources-in-wildfly" rel="nofollow">How to map jpa datasources in WildFly?</a>

However, I am asking for something that would work on all vendors or at least WildFly, Glassfish/Payara, WebSphere Application Server classic, WebSphere Application Server Liberty, TomEE. I am not looking for something that works in a Java SE Unit test.

So far I found that java:comp/env/jdbc/xxx works in WebSphere Application Server and TomEE. There's a mapping exercise (which is expected) to get it working but I cannot get the same to work on GlassFish/Payara and JBoss/WildFly.

More specifically I do not wish to use default data source because for my scenario I am actually working on two different data sources. E.g. for reference data and another for transactional.


If all of the app servers you work with are Java EE 7 compliant, you can use the default data source, which is required per EE7 spec to be available at:


The app server you run on ought to let you customize the configuration of the DefaultDataSource.

Since I'm familiar with WebSphere Liberty, I can point you to this doc for default data sources on Liberty:<br /><a href="https://www.ibm.com/support/knowledgecenter/SSAW57_liberty/com.ibm.websphere.wlp.zseries.doc/ae/twlp_config_dds.html" rel="nofollow">Configuring a default data source</a>

If you are using WebSphere traditional, as of v9.0 it supports Java EE 7, and has a default data source available out of the box (under the spec mandated JNDI name).


If you want to use the same JNDI name that works on all servers, it's best to use resource references, as explained in <a href="https://stackoverflow.com/questions/2887967/what-is-resource-ref-in-web-xml-used-for" rel="nofollow">What is resource-ref in web.xml used for?</a>

Basically, you would define an arbitrary JNDI name (ideally without any java:comp prefix or similar, just something like "myDatasource") and then map it to the concrete JNDI name provided by the target server.You would need to define a server-specific descriptor for each server with the mapping the if the server cannot use the JNDI directly (e.g. glassfish-web.xml for GlassFish/Payara, jboss-web.xml for WildFly, ibm-web-bnd.xml for WebSphere Classic and Liberty). TomEE seems to support references without any prefix, so it should be able to <a href="https://tomee.apache.org/configuring-datasources.html" rel="nofollow">configure a datasource</a> without any additional mapping if you choose a name without a prefix.


  • depth first tree traversal accumulation in clojure
  • Will Route53 private hosted zone work over AWS VPC Peering
  • Testing $http.get() requests in angular
  • Is there any trick about translating BNF to Parsec program?
  • jQuery & CSS - Cut text by height, no truncate
  • Is there an existing gem or script that converts numbers to comp-3/packed decimal format?
  • How to remove Object from array using mongoose
  • Need help manipulating an array in ruby
  • Is storing an OAuth token in cookies bad practise?
  • Michael Hartl RoR tutorial chapter 12 exercise #2
  • How can I encode a filename according to RFC 2231?
  • How can I selectively modify the src attributes of script tags in an HTML document using Perl?
  • Underlying type for Tuple in Swift
  • Is there a limit on how long a cfquery with cfqueryparam can get?
  • Maven use Encrypted passwords in POM
  • JPA/Hibernate - Entity name seems to be important. If I rename to “Bob” works fine
  • Rails 4.1 environment variables not reloading
  • Error in GGally: Error in unit(tic_pos.c, “mm”) : 'x' and 'units' must have leng
  • How to create a custom Powershell operator?
  • insert a picture into database(sqlite) with java code. what should i do?
  • How to convert integer to string and get length of string
  • Bad interaction between Zope2 XML-RPC and AT Image mutator?
  • Blackberry 6: how to detect a long click on track pad?
  • How to pass nginx proxy url for socket
  • Git describe fails to return most recent annotated tag
  • Scala multiline string placeholder
  • PHP buffered output depending on server setting?
  • Functions in global context
  • Asynchronous UI Testing in Xcode With Swift
  • How to delay loading a property with linq to sql external mapping?
  • Display issues when we change from one jquery mobile page to another in firefox
  • Illegal mix of collations for operation for date/time comparison
  • Jenkins: How To Build multiple projects from a TFS repository?
  • Deselecting radio buttons while keeping the View Model in synch
  • How to get a value (ex: baseURL) in every Karate feature?
  • Is possible to count alias result on mysql
  • Check if a string to interpolate provides expected placeholders
  • JSON with duplicate key names losing information when parsed
  • Jquery - Jquery Wysiwyg return html as a string
  • Trying to get generic when generic is not available