|JPA with Eclipselink MySQL jdbc in Eclipse RAP/RCP [message #902928]
||Tue, 21 August 2012 08:51
| Tomas Kramaric
Registered: August 2012
* Eclipse Indigo for RAP RCP devs, RAP 1.4 Target Components, Dali JPA, Jre1.6.0_33 (Java1.6SE) local oracle mysql db
* all JPA (Persistence) + Eclipse link OSGi bundles imported in project (according to eclipse wiki)
* OSGi bundle containing com.mysql.jdbc.Driver class imported in project (latest 5.1.21 ? from Oracle page)
* persistence plugin created via JPA, with jdbc driver,correct mysql db path, correct password & user (added dependency to com.mysql.jdbc bundle)
To avoid ClassLoader problem:
*bundle/plugin com.mysql.jdbc has in its MANIFEST.MF: Bundle-BuddyPolicy: registered
*org.eclipse.persistence.core & org.eclipse.persitence.jpa and mine "persistence bundle" having Buddy registered in their MANIFEST.MF : Eclipse-RegisterBuddy:com.mysql.jdbc + they have dependency to this bundle com.mysql.jdbc
* even after all previous steps I have still: ClassNotFoundException - Driver not found
* connection to localhost mysql db tested from inside Eclipse DatabaseConnection, used same driver from bundle com.mysql.jdbc (class com.mysql.jdbc.Driver) [OK]
* if org.apache.derby Embedded db with Embeded driver is used for persistence (instead of mysql) (with same Buddy policy), problem does not appear - everything works fine
* could it be problem still with ClassLoaders even if BuddyPolicy applied ?
* could it be problem in driver itselves, when its used as OSGi bundle ?
* has somebody ever try to use this com.mysql.osgi bundle in RCP or RAP together with JPA+Eclipselink ?
|Re: JPA with Eclipselink MySQL jdbc in Eclipse RAP/RCP [message #990683 is a reply to message #902928]
||Thu, 13 December 2012 19:17
| Mariusz Cwikla
Registered: January 2012
I think that your problem is not RAP/RCP related, but OSGi generally.
1. First of all, I'd check if your connection-bundle is loaded (use "ss" command in console)
2. On the other hand I would recommend to use Blueprint Container. I'm using Apache Aries as blueprint container + OpenJPA and two databases (H2 and Oracle). It works like a charm.
It was a few months ago, but I remember few facts from time when I tried to evaluate JPA with OSGi. Here are my observations:
- Hibernate have too much problems when using with OSGi
- EclipseLink works great with OSGi, but I also wanted to use JTA, so I looked over Apache Aries. I found out that as it works fine when you use EclipseLink + JDBC but it could not run when I used EclipseLink+Aries+JDBC
- OpenJPA works great with OSGi, but it also works great with Apache Aries. Right now I stick to this.
3. I digged up my very simple project that used EclipseLink with JDBC directly - see attachment. What's needed (example is based on HSQLDB):
- META-INF/MANIFEST.MF: add just this (it's name of your PU)
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
<persistence-unit name="jpa-osgi-resourcelocal" transaction-type="RESOURCE_LOCAL">
<property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:hsql://localhost:9001/mydb"/>
<property name="javax.persistence.jdbc.user" value="sa"/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver"/>
- here is list of bundles from running console - it can show you what's should be present in OSGi environment in order to run EclipseLink:
id State Bundle
0 ACTIVE org.eclipse.osgi_3.8.0.v20120123-1419
1 ACTIVE org.eclipse.equinox.console_1.0.0.v20111215-1210
2 ACTIVE org.eclipse.persistence.asm_3.3.1.v201206041142
7 ACTIVE org.eclipse.persistence.core_2.4.0.v20120608-r11652
9 ACTIVE org.hsqldb.hsqldb_2.2.8
11 ACTIVE org.eclipse.persistence.antlr_3.2.0.v201206041011
12 ACTIVE javax.persistence_2.0.4.v201112161009
14 ACTIVE org.eclipse.osgi.services_3.3.0.v20111117-1210
15 ACTIVE org.apache.felix.gogo.shell_0.8.0.v201110170705
16 ACTIVE org.eclipse.persistence.jpa.osgi_2.4.0.v20120608-r11652
17 ACTIVE org.eclipse.persistence.jpa_2.4.0.v20120608-r11652
20 ACTIVE org.apache.felix.gogo.runtime_0.8.0.v201108120515
31 ACTIVE org.eclipse.persistence.jpa.jpql_2.0.0.v20120608-r11652
34 ACTIVE jpa-osgi-resourcelocal_1.0.0.qualifier
I hope I helped.
[Updated on: Thu, 13 December 2012 19:29]
Report message to a moderator
Powered by FUDForum
. Page generated in 0.06264 seconds