Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/Examples/JPA/WebLogic Web Tutorial"

m (EclipseLink JAR location)
m (EclipseLink JAR location)
Line 49: Line 49:
 
It is not recommended that you distribute eclipselink.jar with your EAR application.
 
It is not recommended that you distribute eclipselink.jar with your EAR application.
  
====Option 1: eclipselink.jar on domain====
+
====Option 1: eclipselink.jar on domain - recommended====
 
To get the server to automatically pick up eclipselink.jar during startup - it should be placed off of ''$WEBLOGIC_HOME/samples/domains/wl_server/lib''  
 
To get the server to automatically pick up eclipselink.jar during startup - it should be placed off of ''$WEBLOGIC_HOME/samples/domains/wl_server/lib''  
  

Revision as of 11:43, 3 September 2008

EclipseLink JPA Deployed on WebLogic 10.0 using Eclipse WTP

If you want to get a small web application running quickly on WebLogic - the services provided by the Web Tools Project pluggin in the Eclipse IDE can take care of the deployment details and set the server into debug mode for you.

This basic example details how to use Eclipse to run/debug a minimum J2EE web application servlet using EclipseLink JPA as the persistence provider. The goal of this example is to detail the minimum steps needed to run EclipseLink inside WebLogic using the Eclipse IDE - at this point no presentation/controller layer such as JSF, Spring or Struts will be used beyond a basic HttpServlet so we can concentrate on the the integration layer JPA setup.

The DALI project was used to generate Entities from a schema with sequences already populated.

Development Environment

Hardware: Windows Vista SP1, HP Core2Quad, 2.4Ghz, 3Gb Ram

Software: Eclipse IDE for Java EE 3.4 M5 Ganymede (Feb 2008) with all 5 packages (DTP 1.6, EMF 2.4, GEF 3.4, WTP 3.0, XSD 2.4), Oracle 11g DB 11.1.0.6.0, Java JDK 1.5.0_11, WebLogic 10.0.1

This example will run fine with Eclipse 3.3 EE and any Database that EclipseLink supports.

Prerequisites

  • Install Eclipse EE
    • I installed a clean version of Eclipse Ganymede M5 with all of WTP 3.0
  • Install a Database
    • In this example I am using Oracle 11g, the table schemas have already been created manually and all entitity java classes have been generated using the Eclipse DALI tool.
  • Install Oracle WebLogic Server Tools for Eclipse
    • bea-wls-tools-2.0.2 plugin works only up to Eclipse 3.4 Ganymede M5 (not the later RC(n) versions)
    • Eclipse 3.3/3.4 EE does not come with the WebLogic server configurations, you must upgrade from the dev2dev site in order to pick up the 10.x server plugins.
    • Either add the 2.0.2 update site URL to your Eclipse 3.4 install, or download the zip file containing the features/plugins directories and overlay on your Eclipse install manually.
    • Alternatively, you may be able to use the "J2EE Preview at localhost" as the server config - however I will need to verify this.

WebLogic configuration Changes

JNDI Datasource Setup

  • You may update config.xml directly - not recommended, or use the admin console wizard to create your JNDI datasource.
    • wls10n/user_projects/domains/base_domain/config/config.xml will contain the following new entry where OracleDS-nnnn-jdbc.xml will contain all the DB properties parameters.
<jdbc-system-resource>
  <name>OracleDS</name>
  <target>AdminServer</target>
  <descriptor-file-name>jdbc/OracleDS-0429-jdbc.xml</descriptor-file-name>
</jdbc-system-resource>

EclipseLink JAR location

It is not recommended that you distribute eclipselink.jar with your EAR application.

Option 1: eclipselink.jar on domain - recommended

To get the server to automatically pick up eclipselink.jar during startup - it should be placed off of $WEBLOGIC_HOME/samples/domains/wl_server/lib

Or if you have created your own default user domain put the jar into the following directory

$WEBLOGIC_HOME/user_projects/domains/base_domain/lib

You will see the following on startup

<Sep 3, 2008 11:22:56 AM EDT> <Notice> <WebLogicServer> <BEA-000395> <Following extensions directory contents added to the end of the classpath:
C:\opt\wls103a\user_projects\domains\base_domain\lib\eclipselink.jar;
C:\opt\wls103a\wlserver_10.3\platform\lib\p13n\p13n-schemas.jar;
C:\opt\wls103a\wlserver_10.3\platform\lib\p13n\p13n_common.jar;
C:\opt\wls103a\wlserver_10.3\platform\lib\p13n\p13n_system.jar;
C:\opt\wls103a\wlserver_10.3\platform\lib\wlp\netuix_common.jar;
C:\opt\wls103a\wlserver_10.3\platform\lib\wlp\netuix_schemas.jar;
C:\opt\wls103a\wlserver_10.3\platform\lib\wlp\netuix_system.jar;
C:\opt\wls103a\wlserver_10.3\platform\lib\wlp\wsrp-client.jar;
C:\opt\wls103a\wlserver_10.3\platform\lib\wlp\wsrp-common.jar> 

Option 2: eclipselink.jar specified at startup

If you do not want to reference eclipselink.jar outside of the WebLogic install then you must modify the startup script that was generated for your domain.

see $C:\opt\wls103a\user_projects\domains\base_domain\bin\startWebLogic.cmd:85.

Note: I haven't preserved anything that may already been set on weblogic.ext.dirs - we should append the eclipselink.jar with a path delimiter - however this web application predeploys and runs fine with the following path addition instead of using option 1 above.

set JAVA_OPTIONS=%JAVA_OPTIONS% -Dweblogic.ext.dirs=c:\eclipselink.jar

See the updated classpath and predeploy logs

<Sep 3, 2008 11:39:40 AM EDT> <Notice> <WebLogicServer> <BEA-000395> <Following extensions directory contents added to the end of the classpath:
C:\eclipselink.jar;
C:\opt\wls103a\wlserver_10.3\platform\lib\p13n\p13n-schemas.jar;C:\opt\wls103a\wlserver_10.3;.....C:\opt\wls103a\wlserver_10.3\platform\lib\wlp\wsrp-common.jar> 
....
[EL Finest]: 2008.09.03 11:39:55.497--ServerSession(32263885)--Thread(Thread[Thread-20,5,Pooled Threads])--Begin predeploying Persistence Unit unified; state Initial; factoryCount 0

Option 3: eclipselink.jar on server - not verified

If using multiple domains you may put eclipselink.jar higher in the classloader tree by dropping it into (TBD - test scenario required).

  • Jar additions to $WEBLOGIC_HOME/wlserver_10.3/server/lib are not automatically picked up by the server.
  • Jar additions to $WEBLOGIC_HOME/user_projects/domains/base_domain/config/lib are not automatically picked up by the server and require configuration.

JDBC JAR location

Jars for Oracle 11, MySQL 5 and Sybase 5.5/6.0 are off their own directories in

$WEBLOGIC_HOME/wlserver_10.[0|3]/server/ext/jdbc

Create server in Eclipse

Open the servers view New | Server | BEA | WebLogic 10.

Eclipse weblogic server screen2.jpg

Create J2EE application

Create your own J2EE Enterprise Application as below. File | new | project | J2EE | Enterprise Application Project Select server, use 5.0 Ear version

Create a new Web and an optional EJB project

Select generate deployment descriptor if you want to change the context-root

  • Path changes
	<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.persistence.core"/>
	<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.persistence.jpa"/>
or
	<classpathentry combineaccessrules="false" kind="src" path="/eclipselink.jar"/>
  • After EAR project creation - reference the org.eclipse.peristence.core and jpa projects or include a reference to eclipselink.jar in your WAR project.
  • If you don't reference the eclipselink.* projects then include a classpath reference to persistence.jar and an Oracle (or other Database) JDBC driver jar for your DB - You will need to put this JDBC driver jar in your WebLogic /domains/wl_server/lib directory as well.

Persistence.xml

  • JTA : Put persistence.xml beside your JPA entities in yourProjectEJB/ejbModule/META-INF
<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">
  <persistence-unit name="unifiedWebLogic" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>OracleDS</jta-data-source>         
    <non-jta-data-source>OracleDS</non-jta-data-source>
    <properties>
      <property name="eclipselink.target-server" value="WebLogic_10"/>
      <property name="eclipselink.logging.level" value="FINEST"/>
    </properties>
  </persistence-unit>
</persistence>
  • RESOURCE_LOCAL : non-JTA : Put persistence.xml beside your JPA entities in yourProjectEJB/ejbModule/META-INF
<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">
  <persistence-unit name="unifiedWebLogic" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <properties>
      <property name="eclipselink.target-server" value="WebLogic_10"/>
      <property name="eclipselink.logging.level" value="FINEST"/>
      <property name="eclipselink.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/>
      <property name="eclipselink.jdbc.platform" value="org.eclipse.persistence.platform.database.oracle.OraclePlatform"/>
      <property name="eclipselink.jdbc.url" value="jdbc:oracle:thin:@localhost:1521:orcl"/>
      <property name="eclipselink.jdbc.user" value="user"/>
      <property name="eclipselink.jdbc.password" value="pw"/>
    </properties>
  </persistence-unit>
</persistence>

Start Server

  • Steps: Select the EAR and [Run on Server].
  • The first "Run on Server" may not start the server, in this case you "Start Server" and then "Run on Server".

Publish EAR

  • Publishing to WebLogic 10 is very simple (you don't require an IDE like Eclipse), once the server is setup you can just drop/remove an EAR in the autodeploy directory to domains/wl_server/autodeploy an application. Or use Eclipse to debug via the 5005 port if the server is managed through WTP.
  • Eclipse WTP will take care of copying the EAR file to the live deploy directory when you either [re-publish] or modify any files while the server is running.
  • You may also use any combination of running the WebLogic server yourself in run or debug mode and using eclipse to publish EAR changes.
  • Depending on your application you will see the following predeploy/deploy logs after running [start server]
    • In your console window you will see one process both for the server and the deploy target.
starting weblogic with Java version:
BEA JRockit(R) (build R27.3.1-1_CR344434-89345-1.5.0_11-20070925-1628-windows-ia32, compiled mode)
[EL Finest]: 2008.05.21 15:54:03.251--ServerSession(7692289)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Begin predeploying Persistence Unit unifiedWebLogic; state Initial; factoryCount 0
[EL Config]: 2008.05.21 15:54:04.048--ServerSession(7692289)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--The alias name for the entity class [class org.eclipse.persistence.example.unified.business.StatLabel] is being defaulted to: StatLabel.
[EL Finer]: 2008.05.21 15:54:04.188--ServerSession(7692289)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Class [org.eclipse.persistence.example.unified.business.StatLabel] registered to be processed by weaver.
<May 21, 2008 3:54:11 PM EDT> <Notice> <WebLogicServer> <BEA-000331> <Started WebLogic Admin Server "examplesServer" for domain "wl_server" running in Development Mode> 

Perform a JPQL query

public class FrontController extends HttpServlet implements Servlet {
	@EJB(beanName="ApplicationService")
	public ApplicationServiceLocal applicationService;
...
 
@Local
public interface ApplicationServiceLocal {
...
 
@Local
@Stateless
public class ApplicationService implements ApplicationServiceLocal {
	@PersistenceContext(unitName="unifiedWebLogic")	
	private EntityManager entityManager;
...
  • Console Output
[EL Finest]: 2008.05.21 15:58:30.112--ServerSession(7692289)--Thread(Thread[[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Weaved persistence (PersistenceEntity) [org.eclipse.persistence.example.unified.business.StatLabel].
[EL Info]: 2008.05.21 15:58:30.798--ServerSession(7692289)--Thread(Thread[[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--EclipseLink, version: Eclipse Persistence Services - 1.0 (Build SNAPSHOT - 20080507)
[EL Info]: 2008.05.21 15:58:30.798--ServerSession(7692289)--Thread(Thread[[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Server: WebLogic Server 10.0 MP1  Thu Oct 18 20:17:44 EDT 2007 1005184 
[EL Fine]: 2008.05.21 15:58:31.985--Thread(Thread[[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Detected Vendor platform: org.eclipse.persistence.platform.database.oracle.Oracle10Platform
[EL Config]: 2008.05.21 15:58:32.016--ServerSession(7692289)--Connection(8272442)--Thread(Thread[[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--connecting(DatabaseLogin(	platform=>Oracle10Platform	user name=> "stat"	datasource URL=> "jdbc:oracle:thin:@localhost:1521:orcl"
[EL Finest]: 2008.05.21 15:58:33.061--UnitOfWork(9354744)--Thread(Thread[[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Execute query ReadAllQuery(org.eclipse.persistence.example.unified.business.StatLabel)
[EL Fine]: 2008.05.21 15:58:33.093--ServerSession(7692289)--Connection(8318645)--Thread(Thread[[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--SELECT ID, DATE_STAMP FROM STAT_LABEL WHERE (ID < ?)
	bind => [200]
[EL Finest]: 2008.05.21 15:58:34.544--UnitOfWork(9354744)--Thread(Thread[[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Register the existing object org.eclipse.persistence.example.unified.business.StatLabel@96976d

  • Browser Output

Eclipselink example jpa weblogic web jpql action cap.jpg

References

Back to the top