Eclipse Indigo, how to autogenerate Entity Meta Model - eclipse

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

Related

Strange issue between Eclipse Mars and Maven

Some context
I am creating a Spring Boot base code application that is in fact separated in three projects/modules:
springbase-core
contains:
custom annotations
custom exceptions
custom generic Spring components
model (entities)
metamodels (generated by maven through the maven-processor-plugin)
utils
depends on: nothing
springbase-data
contains:
data related annotations
services
repositories
data related util classes
depends on: springbase-core
springbase-web
controllers
form classes
filters
listeners
interceptors
JSPs
JSP Tags
etc.
depends on: springbase-data, springbase-core
The problem I am having is that if I have springbase-core in my Eclipse workspace, I'm not able to import metamodels in repository classes in springbase-data. If I remove the springbase-core project (where metamodels reisde) from my Eclipse workspace, it works.
I have also tried copying springbase-core-0.0.1-SNAPSHOT.jar from my .m2 repository, directly at the root of my project (and taking care of adding it in .classpath), and I was able to import metamodels.
When opening springbase-core-0.0.1-SNAPSHOT.jar with WinZip, I can see the metamodels. Building springbase-core with Maven also shows the generated metamodels under /target/metamodel as configured in my pom.xml.
Looks like a glitch between Eclipse and Maven.
Any thoughts?
Here is a solution to my problem: Right click on all projects, click on Maven, and then Disable Workspace Resolution.
That way Maven is going to look for the dependency only from .m2, regardless of what's in my workspace.

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.

JPA Facet cannot be activated in Eclipse

If I try to activate the "JPA Facet" for my Eclipse (Juno) project and point it to a user library containing the JPA libraries (in my case OpenJPA) I get the error:
"The class 'javax.persistence.Entity' is required to be in the selected libraries."
But this class is present there!
"Solution": The JPA libraries were contained in an Eclipse project folder. If I copy it somewhere outside and create another user library with them it works perfectly (although it has exactly the same content as the one before with the libraries located in the Eclipse project!). Seems like an Eclipse bug...
Just create a user library that contains the javax.persistence... JAR in it (It is located in Eclipse/plugins) and add this library at "JPA Implementation"
I'm using Spring Tool Suite (STS). The problem I was facing is that in the default installation the M2E-WTP plugin does not include the Optional component "m2e-wtp - JPA Configurator for WTP".
So I went to Help -> Eclipse Marketplace... and searched "m2e-wtp".
Click on the Installed button and it will become Change. Click on the Change button and select the optional component "m2e-wtp - JPA Configurator for WTP". Apply changes.
This solved for me.

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.

Using EclipseLink 2.3.0 from Target

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