I have a problem with my data persistance. I do not see where is the problem. Can you help me ?
The error in Tomcat:
javax.persistence.PersistenceException: No Persistence provider for EntityManager named miageTP13
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:89)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
dao.impl.TeamDAOImpl.getEntityManager(TeamDAOImpl.java:20)
dao.impl.TeamDAOImpl.insert(TeamDAOImpl.java:36)
controller.TeamController.createTeam(TeamController.java:119)
How is this caused and how can I solve it?
Related
Performing weaving (static or dynamic) results in the following error:
Caused by: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.7.1.v20171221-bd47e8f): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [MyUnit] failed.
Internal Exception: java.lang.NullPointerException
at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:231)
... 20 more
Caused by: java.lang.NullPointerException
at org.eclipse.persistence.sessions.Project.hasSQLResultSetMapping(Project.java:1040)
at org.eclipse.persistence.internal.jpa.metadata.queries.NamedNativeQueryMetadata.hasResultSetMapping(NamedNativeQueryMetadata.java:141)
at org.eclipse.persistence.internal.jpa.metadata.queries.NamedNativeQueryMetadata.process(NamedNativeQueryMetadata.java:172)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.processQueries(MetadataProject.java:1713)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.addNamedQueries(MetadataProcessor.java:153)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:2024)
I didn't get this error with EclipseLink 2.6.5 and if I turn Weaving off everything works fine.
Is there a way to work around it? What triggers the error?
The NPE is a bug, as it isn't performing a null check and throwing a more specific error: This error could only occur if you've specified a named native (SQL) query on your entities that references a SqlResultSetMapping, but you haven't defined any result sets mappings. See https://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/Native#SQL_Result_Set_Mapping for documentation and an example.
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named Employee
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at Emp.Employee_Details.main(Employee_Details.java:74)
It seems like you forgot add persistence provider in persistence.xml. If you use hibernate, it must be something like this:
<provider>org.hibernate.ejb.HibernatePersistence</provider>
I am using Spring Data JPA to develop a Spring MVC app. I built a JPA repository.
public interface AccessReportRepository extends JpaRepository<AccessReport, Long> {
}
I also use Spring Data Mongo along with JPA in my project.
When I run the project, I get this error.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lastDateController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.innolabmm.software.mongotest.springrest.ReadingService com.innolabmm.software.mongotest.springrest.LastDateController.readingService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'readingService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.innolabmm.software.mongotest.springrest.AccessReportRepository com.innolabmm.software.mongotest.springrest.ReadingService.reportRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accessReportRepository': FactoryBean threw exception on object creation; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property flush found for type void
Does anyone have an idea what is going on? I am ready to provide more information if this will help solve the problem. Thanks in advance.
Are you using Spring Boot?
I had the same exception thrown when trying to use JPA and Mongo together, in a Spring Boot application. I found that the Repositories were always being interpreted by both JPA and Mongo, leading to problems as my repositories specifically extend JpaRepository.
I only wanted JPA repositories generated, so added the following to the Application entry point.
#EnableAutoConfiguration(exclude={MongoRepositoriesAutoConfiguration.class})
If you are using MongoDB with JPA (my JPA db is mysql) do this:
create separete packages for domain objects and for repositories (DAOs): i.e. demo.mysql.domain, demo.mysql.dao, demo.mongo.domain, demo.mongo.dao
in your configuration class use these annotations:
#EntityScan(basePackages={"demo.mysql.domain"})
#EnableJpaRepositories(basePackages={"demo.mysql.dao"})
#EnableMongoRepositories(basePackages={"demo.mongo.dao"})
annotate your JPA entities with #Entity and put them all in demo.mysql.domain package
annotate your MongoDB entities with #Document and put them all in demo.mongo.domain package
keep all of MongoDB reporitories in demo.mongo.dao package
keep all JPA repositories in demo.mysql.dao package
all mongo repositories should extend MongoRepository (i.e. public interface TransactionRepository extends MongoRepository)
all JPA repositories should extend JpaRepository (i.e. public interface CityRepository extends JpaRepository)
This is by far the easiest and the cleanest way that I have found (after digging through docs, btw.) to have MongoDB and Mysql working in one Spring Boot app.
That is what I have tried and what works. You could probably use MongoTemplate or extend CrudRepository instead of JpaRepository, or whatever else, try it, it might work.
I am working on the data access layer for rdf. For mapping of java objects to rdf i have used "Empire" tool (by Clark & Parsia).
It is giving error on following line
EntityManager aManager=Persistence.createEntityManagerFactory("oreilly").createEntityManager();
Error:
javax.persistence.PersistenceException: No Persistence provider for EntityManager named oreilly
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:56)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
at Main.main(Main.java:48)
I have set the 0.name=oreilly in properties file and also checked the path of properties file but still its giving the error.
System.setProperty("empire.configuration.file", "examples.empire.config.properties");
EntityManager aManager = Persistence.createEntityManagerFactory("oreilly").createEntityManager();
Ensure you have a JPA implementation such as eclipselink.jar on your classpath.
I am trying out simple JPA example on TomEE 4.0.0 and I am not able to get PersistenceContextType.EXTENDED working
If I make my session bean Stateless and leave PersistenceContextType then it works fine
#PersistenceContext(unitName = "xxx" )
private EntityManager entityManager;
If I keep my session bean as Stateless and then try to use this
#PersistenceContext(unitName = "xxx", type = PersistenceContextType.EXTENDED))
private EntityManager entityManager;
it gives me an error while deploying, which is perfectly fine and in line with expectation.
However now when I make my bean as #Stateful, then also it gives me an error
Managed ejbs are not capable of using EntityManagers with EXTENTED persistence. Convert your bean to a Stateful ejb or update the "java:comp/env/com.testwebservice.TestJPAService/entityManager" PersistenceContext reference to PersistenceContextType.TRANSACTION.
Can some one please help, I am really confused for this
#Stateful EXTENDED persistence contexts are tested in numerous ways in the TomEE build and also in the Java EE TCK.
Likely this is something else completely. We do our best to warn you when you make obvious mistakes as you note with the incorrect combination of #Stateless with PersistenceContextType.EXTENDED
Looking at the JNDI name which contains com.testwebservice.TestJPAService and given the fact it was #Stateless before it was changed to #Stateful, my guess is that this bean is also an #WebService which is illegal. #Stateful beans cannot be #WebService beans. Without a proper check to prevent this mistake, my guess is that the bean is actually being deployed twice; once as a #Stateful bean and once as an pojo #WebService. The pojo web service is the one causing the error.
In case that is the error, I've filed a JIRA for us to explicitly check that condition.