Difference between revisions of "EclipseLink/Examples/JPA/Derby"

From Eclipsepedia

Jump to: navigation, search
m (Running EclipseLink on the Derby Database)
m (Running EclipseLink on the Derby Database)
 
(2 intermediate revisions by one user not shown)
Line 1: Line 1:
 
=Running EclipseLink on the Derby Database=
 
=Running EclipseLink on the Derby Database=
 +
*20110127: update for new Pagination and Sequencing support for Derby 10.6 - 10.7 submitted in bug# [http://bugs.eclipse.org/323897 323897] and [http://bugs.eclipse.org/335464 335464]
 
*Running EclipseLink on derby has several advantages including ease of installation and small footprint for rapid development - and the fact that it is also open source like EclipseLink.
 
*Running EclipseLink on derby has several advantages including ease of installation and small footprint for rapid development - and the fact that it is also open source like EclipseLink.
 
*This tutorial is currently working with Derby 10.5.3.0.
 
*This tutorial is currently working with Derby 10.5.3.0.
Line 32: Line 33:
 
     <class>org.eclipse.persistence.example.jpa.server.business.Cell</class>
 
     <class>org.eclipse.persistence.example.jpa.server.business.Cell</class>
 
     <properties>
 
     <properties>
      <property name="eclipselink.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
 
 
       <property name="eclipselink.target-database" value="Derby"/>             
 
       <property name="eclipselink.target-database" value="Derby"/>             
       <property name="eclipselink.jdbc.url" value="jdbc:derby://localhost:1527/weblogic;create=true"/>
+
       <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
       <property name="eclipselink.jdbc.user" value="APP"/>
+
      <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/weblogic;create=true"/>
       <property name="eclipselink.jdbc.password" value="APP"/>
+
       <property name="javax.persistence.jdbc.user" value="APP"/>
 +
       <property name="javax.persistence.jdbc.password" value="APP"/>
 
       <property name="eclipselink.logging.level" value="ALL"/>             
 
       <property name="eclipselink.logging.level" value="ALL"/>             
 
       <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
 
       <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
Line 44: Line 45:
 
</persistence>
 
</persistence>
 
</source>
 
</source>
 +
 
===Add derby jars===
 
===Add derby jars===
 
*SE: Add '''derbyclient.jar''' to the application classpath
 
*SE: Add '''derbyclient.jar''' to the application classpath
 
*EE: Add derby jars to the application server classpath (Example: for WebLogic place in the modules directory)
 
*EE: Add derby jars to the application server classpath (Example: for WebLogic place in the modules directory)
 +
==Console Output==
 +
You should see something similar to the following in your System.out output.
 +
<pre>
 +
[EL Config]: 2010-01-15 12:22:33.343--ServerSession(11625173)--Connection(17876004)--Thread(Thread[main,5,main])--connecting(DatabaseLogin(
 +
platform=>DerbyPlatform
 +
user name=> "APP"
 +
datasource URL=> "jdbc:derby://localhost:1527/weblogic;create=true"
 +
))
 +
[EL Config]: 2010-01-15 12:22:33.678--ServerSession(11625173)--Connection(12376621)--Thread(Thread[main,5,main])--Connected: jdbc:derby://localhost:1527/weblogic;create=true
 +
User: APP
 +
Database: Apache Derby  Version: 10.5.3.0 - (802917)
 +
Driver: Apache Derby Network Client JDBC Driver  Version: 10.5.3.0 - (802917)
 +
[EL Finest]: 2010-01-15 12:22:33.696--ServerSession(11625173)--Thread(Thread[main,5,main])--sequencing connected, state is NoPreallocation_State
 +
[EL Info]: 2010-01-15 12:22:33.76--ServerSession(11625173)--Thread(Thread[main,5,main])--default-session login successful
 +
</pre>
  
 
==References==
 
==References==
 
*Originated 20091113 for Derby 10.5.3.0
 
*Originated 20091113 for Derby 10.5.3.0

Latest revision as of 12:30, 27 January 2011

Contents

[edit] Running EclipseLink on the Derby Database

  • 20110127: update for new Pagination and Sequencing support for Derby 10.6 - 10.7 submitted in bug# 323897 and 335464
  • Running EclipseLink on derby has several advantages including ease of installation and small footprint for rapid development - and the fact that it is also open source like EclipseLink.
  • This tutorial is currently working with Derby 10.5.3.0.

[edit] Embedded Derby Driver VS Derby Client

[edit] Retrofitting an existing Java SE application to use Derby

[edit] WebLogic Server Console configuration

Weblogic derby jta datasource setup.JPG

[edit] EE persistence.xml

<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="example" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>localJTA</jta-data-source>
        <!-- optional --><class>org.eclipse.persistence.example.business.Cell</class>
        <properties>
            <!-- optional --><property name="eclipselink.target-database" 
                      value="org.eclipse.persistence.platform.database.DerbyPlatform"/>
            <property name="eclipselink.target-server" value="WebLogic_10"/>
            <property name="eclipselink.logging.level" value="FINEST"/>
        </properties>       
    </persistence-unit>
</persistence>

[edit] SE persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<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="dao.create.tables.derby" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>org.eclipse.persistence.example.jpa.server.business.Cell</class>
    <properties>
      <property name="eclipselink.target-database" value="Derby"/>            
      <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
      <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/weblogic;create=true"/>
      <property name="javax.persistence.jdbc.user" value="APP"/>
      <property name="javax.persistence.jdbc.password" value="APP"/>
      <property name="eclipselink.logging.level" value="ALL"/>            
      <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
      <property name="eclipselink.ddl-generation.output-mode" value="database"/>
    </properties>
  </persistence-unit>
</persistence>

[edit] Add derby jars

  • SE: Add derbyclient.jar to the application classpath
  • EE: Add derby jars to the application server classpath (Example: for WebLogic place in the modules directory)

[edit] Console Output

You should see something similar to the following in your System.out output.

[EL Config]: 2010-01-15 12:22:33.343--ServerSession(11625173)--Connection(17876004)--Thread(Thread[main,5,main])--connecting(DatabaseLogin(
	platform=>DerbyPlatform
	user name=> "APP"
	datasource URL=> "jdbc:derby://localhost:1527/weblogic;create=true"
))
[EL Config]: 2010-01-15 12:22:33.678--ServerSession(11625173)--Connection(12376621)--Thread(Thread[main,5,main])--Connected: jdbc:derby://localhost:1527/weblogic;create=true
	User: APP
	Database: Apache Derby  Version: 10.5.3.0 - (802917)
	Driver: Apache Derby Network Client JDBC Driver  Version: 10.5.3.0 - (802917)
[EL Finest]: 2010-01-15 12:22:33.696--ServerSession(11625173)--Thread(Thread[main,5,main])--sequencing connected, state is NoPreallocation_State
[EL Info]: 2010-01-15 12:22:33.76--ServerSession(11625173)--Thread(Thread[main,5,main])--default-session login successful

[edit] References

  • Originated 20091113 for Derby 10.5.3.0