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.
Related
I am refactoring a JEE REST (using JAX-RS 2.0) application as a Spring Boot application. My old app is packaged in a .war and has a jar file with entities and the persistence.xml configuration file for JPA. This jar is copied into WEB-INF/lib directory. I know Spring JPA works a different way and I don't use persistence.xml now but I wonder if I can package my JPA entity classes in a jar and include them in my Spring Boot apps just like I am doing now. This way I can easily reuse that jar in different Spring Boot Applications.
I'm pretty certain you can do this since I have done the same on one of my projects very recently. The only thing you need to do is make sure that you add an #EntityScan annotation on your main Spring Boot config class with the base package of your entities in the JAR.
#EntityScan("my.external.jar.entity.package")
Spring Boot doesn't really care whether the JPA entities are packages as a separate jar or included into the application. Its a runtime framework and in runtime classes can be loaded from the jar (it should reside in BOOT-INF/lib or 'directly' from the *.class files in the spring boot artifact.
Now there is a rule in spring boot, that says that it will scan for beans (including entities) only in the package where your "main" class resides or under it. This is done in order to avoid long process of analysis of, say, third-party classes that you might use. These third-party classes are usually not spring aware at all, at certainly do not contain any spring beans.
Example:
Say, you place your "main" class (the one annotated with #SpringBootApplication) in the package: com.mycompany.myapp
In this case, the following packages will be scanned (just a couple of examples):
com.mycompany.myapp
com.mycompany.myapp.web
com.mycompany.myapp.services.bl
com.mycompany.myapp.whatever.doesnt.matter
...
The following packages won't be scanned however (again, examples, not the full list):
com.mycompany
com.anothercompany
org.hibernate
If you want to to "alter" this default rule and place the entities in the package that doesn't adhere this convention, for example com.mycompany.jpa.entities then you should indeed use #EntityScan annotation as our colleagues have already suggested.
You can read about this topic here. You might also need to get familiar with #EnableJpaRepositories if you're using spring data but, while related, its a different topic.
In my case I had this problem, and after importing the library in the application's pom.xml, in the SpringBoot Project Main class, insert an #EntityScan annotation with the first package and *. Like this: #EntityScan ("br.*")
I want to use JPA to create an entity class that can be used with the persistence context to access my db2 nosql database. The problem is the #NoSql annotation is not being found.
As per http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/NoSQL/Configuring, I:
Created a web project
Enabled JPA via project properties-> Project Facets -> Check mark JPA v2.1
Under Project properties -> JPA -> Set Platform to EclipseLink 2.5x, Set JPA Implementation to Library Provided by Target Runtime
Setup server.xml with the datasource and the persistence.xml
I have java.persistence.org but not java.persistence.org.oracle.nosql. I'm not sure if I am suppose to download it or it should already be setup. And I also do not know how to use maven (and I would prefer not to).
Most tutorials online either only show HOW to use (and not configure) or use mysql connector and somewhere in the project config it just works. I greatly appreciate assistance!
I solved the problem by following this blog post: https://blogs.oracle.com/NoSQL/entry/eclipselink_jpa_and_oracle_nosql.
Excerpt:
Now at first glance it looks like EclipseLink 2.5 includes support for
NoSQL databases right out of the box, but in fact if you look closely
there is another specific NoSQL plugin download necessary. Download,
unzip and save this plugin in a directory e.g. /nosql-plugin . Later
you’ll need to get some libraries from it.
So go here to get the jar files and import the following into your project
org.eclipse.persistence.nosql_2.5.0*.jar
org.eclipse.persistence.oracle.nosql_2.5.0*.jar
javax.resource_1.5.0*.jar
To import go right-click project -> properties -> java build path -> Libraries tab -> Add External Jar -> Navigate to the jar files and import
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
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.
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