5 Using TopLink with JBoss 7 Application Server
This chapter includess the following sections:
Use Case
TopLink can be used with a number of popular Java EE application servers, including JBoss Application Server.
Solution
Configure JBoss to use EclipseLink runtime, and deploy applications developed using EclipseLink APIs.
Components
-
TopLink 12c (12.1.2.0.0) or later.
Note:
TopLink's core functionality is provided by EclipseLink, the open source persistence framework from the Eclipse Foundation. EclipseLink implements Java Persistence API (JPA), Java Architecture for XML Binding (JAXB), and other standards-based persistence technologies, plus extensions to those standards. TopLink includes all of EclipseLink, plus additional functionality from Oracle.
-
EclipseLink 2.4 or later.
-
JBoss Application Server 7.x.
-
A compliant Java Database Connectivity (JDBC) database, such as Oracle Database, Oracle Express, MySQL, the HSQL database embedded in JBoss Application Server, etc.
Introduction to the Solution
JBoss Application Server implements the Java Platform, Enterprise Edition (Java EE). JBoss 7 fully supports Java EE 6, while JBoss 6 officially supports only the Java EE 6 Web Profile.
By configuring JBoss to support EclipseLink, you can take advantage of EclipseLink's full support for Java Persistence API (JPA), Java Architecture for XML Binding (JAXB), including EclipseLink's extensions to those technologies, as well as EclipseLink Database Web Services (DBWS) to access to relational database artifacts via a Web service.
Implementing the Solution
To develop, deploy and run EclipseLink applications in JBoss Application Server 7, you must create EclipseLink as a module of JBoss. You must also create other modules, such as a JDBC driver, etc., in order to run applications.
This section contains the following tasks for using EclipseLink with JBoss 7.1:
Task 1: Prerequisites
Ensure that you have installed the following components:
-
JBoss, version 7 or later. These instructions are based on JBoss release 7.1.1.
Download JBoss from
http://www.jboss.org/jbossas/downloads/
. The version of JBoss must be identified as "Certified Java EE6." Version 7.1.1 or later is recommended. -
TopLink 12c (12.1.2.0.0) or later.
Download TopLink from
http://www.oracle.com/technetwork/middleware/toplink/downloads/index.html
.EclipseLink 2.4 or later.
Download EclipseLink from
http://www.eclipse.org/eclipselink/downloads/
. -
Any compliant Java Database Connectivity (JDBC) database including Oracle Database, Oracle Express, MySQL, the HSQL database embedded in JBoss Application Server, and so on.
Note:
Oracle XML DB (XDB) and JBoss Application Server both use port
8080
by default. If you have both available at the same URI, for examplelocalhost
, you must reconfigure one or the other to use a different port, for example8081
.For the Oracle Database, see
http://www.oracle.com/technetwork/database/enterprise-edition/overview/index.html
. For the Oracle Database, Express Edition, seehttp://www.oracle.com/technetwork/database/express-edition/overview/index.html
. For MySQL, seehttp://www.oracle.com/us/products/mysql/index.html
. For information about the embedded HSQL database, see the JBoss documentation. -
While it is not required, you may want to use a Java development environment (IDE) for convenience during development. For example JDeveloper, Oracle Enterprise Pack for Eclipse, and NetBeans all provide sophisticated Java EE development tools that support TopLink.
For JDeveloper, see
http://www.oracle.com/technetwork/developer-tools/jdev/downloads/index.html
. For Oracle Enterprise Pack for Eclipse, seehttp://www.oracle.com/technetwork/developer-tools/eclipse/overview/index.html
. For NetBeans, seehttps://www.oracle.com/tools/technologies/netbeans-ide.html
.
Task 3: Add ojdbc6.jar as a Module in JBoss
Add the Oracle thin driver ojdbc6.jar
as a module within JBoss, as follows:
Task 4: Create the Driver Definition and the Datasource
Create the driver definition and create the datasource.
The following instructions tell how to configure JBoss for running in standalome mode, using the standalone.xml
configuration file. For instructions on how to use domain.xml
to configure JBoss for running in domain mode, see the JBoss documentation.
<subsystem xmlns="urn:jboss:domain:datasources:1.0"> <datasources> <datasource jndi-name="java:/EclipseLinkDS" pool-name="EclipseLinkDS" enabled="true" jta="true" use-java-context="true" use-ccm="true"> <connection-url>jdbc:oracle:thin:node_name.example.com:1521:TOPLINK</connection-url> <driver>oracle</driver> <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation> <pool> <prefill>true</prefill> <use-strict-min>false</use-strict-min> <flush-strategy>FailingConnectionOnly</flush-strategy> </pool> <security> <user-name>Smith</user-name> <password>password</password> </security> </datasource> <driver name="oracle" module="com.oracle.ojdbc6"> <xa-datasource-class>oracle.jdbc.OracleDriver</xa-datasource-class> </driver> </datasources> </subsystem>
Task 5: Create Users
Starting with JBoss Application Server 7.1, you must create an Application User to get started, because remote access to the JNDI tree is secured by default, and you must provide login credentials. Therefore, at a minimum, you just create an Application User to be able to deploy an application to the server. If you want to use the JBoss administration console for administration tasks, for example to view the JNDI tree, you must also create an Administration User.
To create user credentials, use the JBoss add-user.bat
utility, located in JBOSS_HOME
\bin\
.
For more information about security in JBoss Application Server, refer to the JBoss documentation.
Task 6: Modify JBoss Properties
Modify JBoss properties, as follows:
## JBoss-7.x server.factory=org.jboss.naming.remote.client.InitialContextFactory java.naming.factory.url.pkgs=org.jboss.ejb.client.naming server.depend=jboss-client.jar jboss.server=${jboss.home}/standalone server.lib=${jboss.home}/bin/client server.url=remote://localhost:4447 server.user=usera server.pwd=passworda jboss.naming.client.ejb.context=true
Task 7: Other Requirements
- Add
junit.jar
in theear
under the\lib
directory. - Because of a classloading issue in JBoss, you must list all your entity classes in
persistence.xml
. You can use either<class>
elements or a global<exclude-unlisted-classes>false</exclude-unlisted-classes>
element. - Add both
jndi.properties
andjboss-ejb-client.properties
in the client classpath.
Additional Resources
See the following resources for more information about the technologies and tools used to implement the solutions in this chapter:
-
JBoss Community at
http://www.jboss.org
.