Hey Cristiano,
Thanks for sharing your experiences - it's always nice to get descriptions of working solutions like this! If you have it ready for publishing and fancy having it included in the ServiceMix default example set, we love contributions like this ;) With regards to your question: I don't have any experience with EclipseLink whatsoever, but when I use OpenJPA I usually prefer compile-time enhancement of those classes instead of the runtime variant. That being said: there are some efforts to standardize how weaving can happen in OSGi (e.g. OSGi R4.3 introduces the WeavingHook API). You could perhaps take a look at how Aries uses this technique to do weaving for OpenJPA (at http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/weaving/) and I suspect Gemini/EclipseLink has a similar solution implemented somewhere. Regards, Gert Vanthienen On Wed, Aug 7, 2013 at 8:21 PM, Cristiano Costantini <[email protected]> wrote: > Hi All, > > it is days I am investigating how to use JPA with Eclipselink under > ServiceMix using an approach that satisfy me. I prefer not to use > karaf-enterprise (at least until I fully understand it) and so I avoided > using the Servicemix's "jpa" feature, and I focused on spring-orm, that is > a available as a feature too in the standard assembly. I also prefer it as > my applications use spring and not blueprint for deployment. > > So, today I've achieved some significant result as my test application is > working and successfully writing and reading from both an HSQLDB and Mysql > from within a bundle running on ServiceMix 4.5.2 with Eclipselink 2.5.0. > > Even if it works, there are some weird aspect that I would like the have > some feedback about, but I will explain fully my test application in the > hope it may be helpful for someone else. > > (I'm writing a lot of code in the mail, I'm going to leave some days for > holidays, when I'm back, if someone ask for it, I can try to clean and > publish this test application as an example for others to work on) > > > 1. As first step, I show the dependencies I installed on servicemix. > I've created a feature with my bundles plus all the dependencies: > > <feature name="osgijpa-test" version="1.0"> > <feature>spring-orm</feature> > > <bundle>mvn:mysql/mysql-connector-java/5.1.26</bundle> > <bundle>mvn:org.hsqldb/hsqldb/2.2.9</bundle> > > <bundle>mvn:net.cristcost.test/springjdbc-mysql-fragment/1.0-SNAPSHOT</bundle> > > <bundle>mvn:org.eclipse.persistence/javax.persistence/2.1.0</bundle> > > <bundle>mvn:org.eclipse.persistence/org.eclipse.persistence.antlr/2.5.0</bundle> > > <bundle>mvn:org.eclipse.persistence/org.eclipse.persistence.asm/2.5.0</bundle> > > <bundle>mvn:org.eclipse.persistence/org.eclipse.persistence.core/2.5.0</bundle> > > <bundle>mvn:org.eclipse.persistence/org.eclipse.persistence.jpa.jpql/2.5.0</bundle> > > <bundle>mvn:org.eclipse.persistence/org.eclipse.persistence.jpa/2.5.0</bundle> > > > > <bundle>mvn:net.cristcost.test/osgijpa-testapp-bundle/1.0-SNAPSHOT</bundle> > </feature> > > The test app is the last bundle in the list. Some relevant things to note: > a. spring-orm also install spring-jdbc > b. for mysql, only recent driver are osgi ready - I was using version 5.1.6 > which wasn't > c. spring-jdbc does not support out of the box mysql (see > http://planet.jboss.org/post/how_to_use_jdbc_driver_in_osgi_container), you > need to create a fragment that extends it and I did by creating a bundle > (springjdbc-mysql-fragment) which actually is all about configuring the > maven-bundle-plugin in the pom.xml with the following two options: > <Fragment-Host>org.springframework.jdbc</Fragment-Host> > <Import-Package>com.mysql.jdbc</Import-Package> > > Open question: > - why does spring-jdbc does not support out of the box mysql by importing > its driver package as it does for so many other drivers? > > > 2. The persistence unit I am using in servicemix: > <persistence-unit name="test-pu" transaction-type="RESOURCE_LOCAL"> > <class>net.cristcost.test.TestEntity</class> > </persistence-unit> > > all the rest of the configuration is passed by spring-orm in the spring's > beans configuration file. > The file is deployed within the META-INF folder of the > osgijpa-testapp-bundle bundle. > > 3. The TestEntity class is a simple class used for test purposes: > @Entity > @Table(name = "\"test_entities\"") > public class TestEntity { > public TestEntity() {} > public TestEntity(String id) {this.id = id; this.calls = 0; } > > @Id > @Column(name = "\"id\"", unique = true, nullable = false) > public String id; > > @Column(name = "\"description\"") > public String description; > > @Column(name = "\"time\"") > @Temporal(TemporalType.TIMESTAMP) > public Date time; > > @Column(name = "\"calls\"") > public int calls; > > @Lob > @Column(name = "\"value\"", nullable = true) > public byte[] value; > } > > > 4. I wrote a test application that was possible to execute both in a bundle > in servicemix and outside, in simple java console application. Omitting the > code for bootstrap, here is the > > > Regards, > Cristiano
