I have createdd an EJB project for writing Entites,DAO and Facade classes. But There is no any persistence.xml file in my project. Otherwise I must create a persistence.xml.
Eclipse will only include a persistence.xml file if you add the JPA facet to the project. Right-click the EJB project, go to "Project Facets" and check the box next to "JPA".
Make sure you enable the Dynamic Web Module 3.0 facet in your project.
Either that, or add it manually. It's doesn't make a difference.
Related
I am using Maven 3.3.9 and created a Maven Web Project in Spring tool suite and using Eclipse.
Recently I went through a Tutorial for configuring JPA with maven project.
Tutorial showing JPA configuration
I successfully configured Database connection using EclipseLink2.5
PROBLEM I AM FACING IS
After I click ok followed by configuring JPA 2.1 using project Facet properties. Persistence.xml is created automatically under META-INF of src/main/java instead of src/main/resource location.
Is this correct ??
I had already researched a lot on this, in every blog it is mentioned that META-INF should be placed under src/main/java and not under src/main/resource.
Then why is it every time I create a Maven project and configure JPA from Project Facet, Its ends up automatically creation under src/main/java.
please refer my screenshot.
So should I remove this folder META-INF/Persistence.xml from src/main/java and paste it manually under src/main/resource.
I always move META-INF to src/main/resources. Everything is going to be happier with things configured that way.
Where do I put META-INF in Eclipse?.
In eclipse, I created a JPA project with my entities and repository's.
Now I want to create a Dynamic web project with my servlets and jsp's.
How do I get both to work with each other?
I would say make a jar from my JPA project and import it in the Dynamic Web Project where I load it on the build path.
I tried this but I get a "The import ...... cannot be resolved" error
Is there a specific location I need to place this Jar?
Dont add it as a jar , add in build path as Reference Project
I got this to work by adding the jar in the WebContent/WEB-INF/lib folder. You don't need to add to the build path, just place your jar's here and your IDE will use them when needed.
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 have added new servlet to eclipse project with it's wizard and wizard also asked for servlet mapping. Now I can see this mapping in project explorer tree under Deployment descriptor - Servlet mappings, but web.xml does not contain this mapping.
Is this an eclipse bug or mappings are stored somewhere else nowadays?
Mappings do work.
Eclipse is Indigo.
Tomcat is 7.0
Mappings are set with #WebServlet annotation now.
I'm trying to get a new Enterprise Application Project set up in Eclipse using Glassfish as my app server and I'm seeing the following warning:
Classpath entry eclipse.fproj.jdt.libprov.osgi/jpt.jpa is marked for publish/export but is not exported on the project classpath. Classpath visibility within Eclipse and at runtime will differ.
I've got the Java Persistence 1.0 facet enabled on my EJB project and I'm pretty sure this is what's causing my problems. I've done a lot of searching, but to no avail.
Solved it. I had it marked as a Java EE module dependency, but I didn't have it selected for export. In the project properties window I went to Java Build Path > Order and Export and placed a check next to the entry for EclipseLink 1.1.x.