Using EclipseLink 2.3.0 from Target - eclipse-rcp

I want to use EclipseLink 2.3.0 (as provided with Indigo, resp. the Update Site target provided on http://www.eclipse.org/eclipselink/downloads/) in an Eclipse RCP application.
If I include the EclipseLink libraries specifically in a Plug-In by means of creating a lib folder, stuffing them all in and adding them to the classpath, all the Entities I have in the Plug-In are being found and registered.
If I however switch to using the target distributed EclipseLink Implementation, by adding javax.persistence and org.eclipse.persistence.jpa, the connection to the database is readily built... however NONE of the Entities are found! The occuring message always is:
[EL Warning]: The collection of metamodel types is empty. Model classes may not have been found during entity search for Java SE and some Java EE container managed persistence units. Please verify that your entity classes are referenced in persistence.xml using either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element
My persistence.xml however denotes the respective class, as it is being found when I use the manual libraries! This is rather confusing, any hint on this? :) THX

Take a look at the EclipseLink OSGi examples on the Eclispe wiki for details on how to develop in PDE, how to enable byte code weaving, and an RCP example.
http://wiki.eclipse.org/EclipseLink/Examples/OSGi
--Shaun

Related

Is possible to make a library jpa based?

I'm looking to create some projects with common classes for every other project I create, web or standard.
In eclipse I'd already created two projects with the maven quickstart archetype without the jpa facet, but with the eclipselink libraries in the maven POM to anotate entities and jpa stuff. One project is for generic JPA access and another project for security (user entities, user services, user repository) that uses the JPA access project.
Then I create a 3rd project with the same archetype from last 2 project for testing the previous 2, but this have the JPA facet and the Persistence.xml. When I try to do something JPA related, it says the metamodel is empty. Then I found on the internet and the documentation says I have to use the tag in my persistence.xml, but I dont know how since Im including the previous two project in the build path of eclipse, not exactly any jar file. How can I achieve this?
Excuse my english translation.
You probably need an Composite Peristence Unit. Also, it will probably require some care in your built/deployment scripts.

Eclipse Indigo, how to autogenerate Entity Meta Model

I have read this on how to auto-generate the Entity Meta Model, but I think there is something wrong.
I have: Eclipse Indigo SR2, build 20120216-1857 and configured the "Annotation Processor" as specified here. To the factory path I have added ONLY these jars
hibernate-jpamodelgen-1.2.0.Final.jar (taken from here)
hibernate-jpa-2.0-api-1.0.1.Final.jar (taken from the zip archive of Hibernate ORM 4.1.0 from here)
I suppose after configuring this for my the EJB project (I did not do that for my Web or EAR Project), the project gets rebuild and the Meta Model Classes will be autogenerated, without clicking on another button, is that right?
If everything should have worked, do you have any clues on what could go wrong?
Notes:
I see absolutely no messages from any annotation processors in the "Error Log" Eclipse View.
My persistence.xml file is in the ejbModule/META-INF/persistence.xml
All my entities extend an Abstract class, imported in the project with svn:externals.
My entities are annotated with #Entity, and that's all.
The problem is that the project has also AspectJ compatibility, which makes the Project use another compiler. More details on this bug here.
Beside that, you could (bun not mandatory you will) get an NullPointerException (see the "Error Log" Eclipse View) if you have at least an Abstract Class in your project.
You just need to select the source folder of the generated metamodel on your Project -> Properties -> JPA

why can't my EAR project see the annotated EJBs and Entities in my JPA project?

I'm using IBM RAD 7 (aka Eclipse 3.4) and WebSphere 7.
I have a workspace with a basic EJB setup; projects TestEAR, TestEJB, TestJPA, TestWeb.
I can annotate an ejb ("#Stateless EntityService") in the TestEJB project and it works fine. But if I put an ejb ("#Stateless EntityDAO") in the TestJPA project it doesn't get injected in the EntityService. If I move EntityDAO to the TestEJB project it works fine.
Also, if I annotate a class an entity ("#Entity MyEntity") it is not known as an entity to the container (I get a "not recognized entity" ... "Known entity types: []" error). But if I add a my.domain.MyEntity tag to the TestEJB's persistence.xml it works fine.
QUESTION: Why can't the TestEJB project recognize annotated classes in the TestJPA project?
NOTE: There is no "Deployment Assembly" tab in Eclipse 3.4, but there is a "Java EE Module Dependencies" tab (TestEAR > Properties > Java EE Module Dependencies); I checked and all projects are in the list and checked (ie. TestEJB, TestJPA, TestWeb).
Any help is greatly appreciated! This one has me truly stumped.
Thanks,
Rob
Seems there are a few questions here...
For your TestEJB project not using TestJPA beans make sure both are listed as an <ejb> module and not <jar> module in your application.xml file in TestEAR. Also make sure they are both part of the EAR.
For the No Known Entity types if that error is appearing within RSA you might want to right click on the project and look for "JPA Tools" and select "Configure JPA entities", if you do not see "JPA Tools" ensure JPA facets are enabled for that project. If it is occuring on the server (WAS I presume) make sure the following line is not in your persistence.xml <exclude-unlisted-classes>true</exclude-unlisted-classes> or all classes will need to be listed therein, not necessarily a bad thing.
Unless it is absolutely critical I would store your EJBs and Entities in the same project for simplicity.

Seam Gives Unknow Entity Exception For Entities in Jars

I am trying to use Seam to persist my jpa entities, when I reference an entity that is in a jar seam says unknown entity. I don't want to add all classes in persistence.xml I want seam to scan my jars and auto detect entities (as done by spring).
What am I missing?
It actually depends a lot on the environment of your application.
If it's Java SE (for example war packaged application deployed on tomcat), your jars are not scanned for entities that compose your persistence unit. Those classes are seen as normal java classes, entity manager doesn't care about them that much... And you have to point them manually, or switch to Java EE and ear...

In an OSGi environment, how are the classpaths and classloaders set up?

I'm confused about class visibility in OSGi. I'm running Apache Felix and loading the following bundles:
the antlr, asm, jpa and core bundles from eclipselink
an OSGi-fied jar for javax.persistence 1.99
an OSGi-fied jar with the com.mysql.jdbc driver
a bundle of my own that contains annotated entity classes and a persistence.xml
another bundle of my own that calls Persistence.createEntityManagerFactory(String, Map)
Now, what I'm confused about is which bundle must be able to see the MySQL driver. I thought this would be the bundle creating the EntityManagerFactory, but I get ClassNotFound errors when I import in that manifest. Next, I tried importing it from the eclipselink jpa bundle's manifest, but wrong again. Only when I import it from the manifest of the bundle containing the persistence unit (entity classes and persistence.xml), it works.
So, seemingly the database driver is looked up by the clasloader for the PU's bundle, but that doesn't make sense to me. What's going on?
I can't seem to find a straightforward documentation for this. These slides give some hints, but aren't exactly comprehensive.
I'm familiar with the OSGi classpath issues around Hibernate and JDBC and I can give you my reasoning on what's happening based on the slides you linked to.
I'm assuming you've added the JDBC driver entry to the persistence.xml inside your PU bundle?
EclipseLink is using the extender pattern to do work on the PU bundle's behalf. The extender is listening for bundles starting, checking if they have a persistence.xml and then doing the work of setting it up. It expects the PU bundle to import all the types you may reference in the persistence.xml, including the JDBC driver.
Think about it. The EclipseLink bundle won't import every known JDBC driver (and it shouldn't) - only your bundles can know which database driver they need, so it's reasonable to expect your PU bundle to import the JDBC driver class.
You shouldn't need to modify the manifests of the 3rd-party libraries if they are already OSGi-ified, such as EclipseLink.
I found this pdf to be quite informative regarding classloading:
http://www.martinlippert.org/events/WJAX2008-ClassloadingTypeVisibilityOSGi.pdf