Hey I'm getting a persistence provide not found exception the code for my persistence.xml is
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="GWTSales"
transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.jeroennouws.sales.beans.Branch</class>
<class>com.jeroennouws.sales.beans.Customer</class>
<class>com.jeroennouws.sales.beans.Employee</class>
<class>com.jeroennouws.sales.beans.Product</class>
<class>com.jeroennouws.sales.beans.Purchase</class>
<class>com.jeroennouws.sales.beans.PurchaseDetail</class>
<class>com.jeroennouws.sales.beans.PurchaseDetailPK</class>
<class>com.jeroennouws.sales.beans.Sale</class>
<class>com.jeroennouws.sales.beans.SalesDesk</class>
<class>com.jeroennouws.sales.beans.SalesDetail</class>
<class>com.jeroennouws.sales.beans.SalesDetailPK</class>
<class>com.jeroennouws.sales.beans.Stock</class>
<class>com.jeroennouws.sales.beans.Supplier</class>
<class>com.jeroennouws.sales.beans.User</class>
<properties>
<property name="eclipselink.jdbc.password" value="" />
<property name="eclipselink.jdbc.user" value="root" />
<property name="eclipselink.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="eclipselink.jdbc.url" value="jdbc:mysql://localhost:3306/sales" />
<property name="eclipselink.logging.level" value="INFO" />
</properties>
</persistence-unit>
</persistence>
and the code that generates this exception is
public BranchJpaController() {
emf = Persistence.createEntityManagerFactory("GWTSales");
}
I have tried all different kinds of things by now, eclipselink jar file is in my WEB-INF/lib folder and my persistence.xml file is in my src/META-INF folder.
Does this has something to do with the GWT Jetty server in the eclipse plugin or am I missing something?
Check if the MySQL JDBC Driver is in your WEB-INF/lib folder.
I hope it helps.
Related
I have created a Maven project with some services that use JPA to connect to my database, this project contains the file persistence.xml with all the config needed.
Now I want to import the jar of that project into a new Spring Boot project in order to use all those services, but when I run the Spring Boot project I get an error.
I have tried to import my services jar in another (non Spring Boot) project and that works, so I think that some config of Spring Boot may be overriding mine.
I have my services project dependency on my pom as follows:
<dependency>
<groupId>org.test.services</groupId>
<artifactId>ServicesProject</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
My persistence.xml file has this config:
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="toplink.logging.level" value="INFO"/>
<property name="toplink.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
<property name="hibernate.connection.url" value="jdbc:oracle:thin://localhost:l521/orcl"/>
<property name="hibernate.connection.password" value="password"/>
<property name="hibernate.connection.username" value="user"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.globally_quoted_identifiers" value="true" />
</properties>
</persistence-unit>
</persistence>
I get this error when I run the Spring Boot app:
javax.persistence.PersistenceException: No Persistence provider for EntityManager named default
I am trying to connect to sql server using JPA and hibernate with an Eclipse Maven project. I've tried moving the persistence.xml file to various locations but it doesn't seem to help.
My persistence.xml file is
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="Trades" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:sqlserver:/Trades\SQL00;databaseName=Trades" />
<property name="javax.persistence.jdbc.user" value="sa" />
<property name="javax.persistence.jdbc.password" value="dev" />
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
<property name="show_sql" value="true"/>
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>
</properties>
</persistence-unit>
</persistence>
and my code is as follows and is located in src/main/resources/META-INF
public static void main(String[] args) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("Trades");
System.out.println();
}
I have attached a screenshot which shows my eclipse set up
I solved this, turned out that Maven must have downloaded corrupt libraries - I was alerted this when I was unable to view the source for some classes in the Hibernates jars. I deleted the jars in my .m2 directory and when the jars were refreshed, it worked fine. A bit of tricky one.
I keep getting
java.lang.ClassNotFoundException: Could not load requested class : com.ibm.db2.jcc.DB2Driver
when trying to connect to a DB2 database using Hibernate. The driver jar is referenced as an external library:
Image of Eclipse's "Referenced Library" folder
It also shows up in the classpath:
classpathentry kind="lib" path="C:/Program Files (x86)/IBM/SQLLIB/java/db2jcc.jar"/>
I can also access the class by importing it in the source code. My persistence.xml looks as follows:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="name" transaction-type="RESOURCE_LOCAL">
<description>Persistence Unit</description>
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>MyClass</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.ibm.db2.jcc.DB2Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:db2://url" />
<property name="javax.persistence.jdbc.user" value="user" />
<property name="javax.persistence.jdbc.password" value="password" />
<property name="hibernate.dialect" value="org.hibernate.dialect.DB2Dialect" />
<property name="hibernate.hbm2ddl.auto" value="create" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="true" />
</properties>
</persistence-unit>
</persistence>
My suspicion why this does not work is that the class is contained in an external library and not as a maven dependency, because when I replace the DB2 driver by net.ucanaccess.jdbc.UcanaccessDriver (which is contained in a Maven package), the class will be found just fine.
Any idea what I am doing wrong here?
when you are using com.ibm.db2.jcc.DB2Driver' make sure db2jcc.jar & db2jcc_license_cu.jar are in your classpath.Please add both the jar in your classpath and give a try.
The problem was that I was using the Maven exec plugin to run the main class. W/o using Maven, it works fine...
I have gone though https://www.playframework.com/documentation/2.5.x/JavaJPA
But it doesn't feel like a stardard way. I would like fill my jdbc connection in persistence.xml instead of application.conf
like this
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="TestPersistence"
transaction-type="RESOURCE_LOCAL">
<class>com.example.pojo.Employee</class>
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<non-jta-data-source>DefaultDS</non-jta-data-source>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url"
value="jdbc:mysql://localhost:3306/jpadb" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password"
value="mukesh" />
<!-- EclipseLink should create the database schema automatically -->
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode"
value="database" />
</properties>
</persistence-unit>
</persistence>
instead of filling the jdbc connection in application.conf like
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost:3306/jpadb"
db.default.user=root
db.default.password="mukesh"
db.default.jndiName=DefaultDS
jpa.default=TestPersistence
Also if there is no other way to get jdbc connection in persistence.xml how can we define more than one jdbc connection in application.conf. like if i have a mysql for users and oracle db for posts.
NOTE: the source code posted are just dummy copied from public domain to show the briefly problem.
You don't have to use Play's DB module. You can have your own module defined, and load your database connection and run it in isolation.
I would check out https://github.com/playframework/play-isolated-slick as an example -- here the UserDAO is bound through to SlickDAO in the Play module:
https://github.com/playframework/play-isolated-slick/blob/master/modules/play/app/Module.scala#L19
and the database provider is provided:
https://github.com/playframework/play-isolated-slick/blob/master/modules/play/app/Module.scala#L27
but you don't have to use Database.forConfig("myapp.database") -- you can define any config you feel like.
My development environment (IBM RAD 8 + WAS 8) is complaining that my project does not have a persistence.xml file. Still it seems that I can build and run my project. Is that file required and if a add one such file to make my project pass validation, what should be in that file?
The project is a web project that uses session beans and entity beans from other projects and this persistence.xml error is the only error in the project so I'd be glad to get rid of it.
Thanks for any help
Update
I searched my files for persistence.xml and it showed up in src/ and bin/ of the EJB project while the web project with servlets and jsp does not have a persistence.xml, according to my colleague the web project is using the persistence.xml from the EJB project i.e:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="PandoraArendeWeb" transaction-type="JTA">
<jta-data-source>jdbc/Mainframe_TEST_ADBUTV2</jta-data-source>
<class>se.prv.pandora.arendeprocess.entity.PRVNummer</class>
<class>se.prv.pandora.arendeprocess.entity.Ansokan</class>
<class>se.prv.pandora.arendeprocess.entity.NatAnsokan</class>
<class>se.prv.pandora.arendeprocess.entity.PctAnsokan</class>
<class>se.prv.pandora.arendeprocess.entity.ArendePerson</class>
<class>se.prv.pandora.arendeprocess.entity.Nyregistrering</class>
<class>se.prv.pandora.arendeprocess.entity.Anstalld</class>
<class>se.prv.pandora.arendeprocess.entity.Handlaggare</class>
<class>se.prv.pandora.arendeprocess.entity.OrgElement</class>
<class>se.prv.pandora.arendeprocess.entity.FysiskHandlaggare</class>
<class>se.prv.pandora.arendeprocess.entity.AnsvarigHandlaggare</class>
<class>se.prv.pandora.arendeprocess.entity.AnsvarigFysiskHandlaggare</class>
<class>se.prv.pandora.arendeprocess.entity.TeknikOmrade</class>
<class>se.prv.pandora.arendeprocess.entity.Person</class>
<class>se.prv.pandora.arendeprocess.entity.PRVNummerPerson</class>
<class>se.prv.pandora.arendeprocess.entity.Notering</class>
<class>se.prv.pandora.arendeprocess.entity.Lock</class>
<class>se.prv.pandora.arendeprocess.entity.LandKod</class>
<class>se.prv.pandora.arendeprocess.entity.ArbetsMomentLog</class>
<class>se.prv.pandora.arendeprocess.entity.SystemTypDel</class>
<class>se.prv.pandora.arendeprocess.entity.ArbetsMoment</class>
<class>se.prv.pandora.arendeprocess.entity.UnderStatus</class>
<class>se.prv.pandora.arendeprocess.entity.PatPers</class>
<class>se.prv.pandora.arendeprocess.entity.PrvLandP</class>
<class>se.prv.pandora.arendeprocess.entity.PkaPerln</class>
<class>se.prv.pandora.arendeprocess.entity.PctnPerl</class>
<class>se.prv.pandora.arendeprocess.entity.PersonToPatPersKoppl</class>
<class>se.prv.pandora.arendeprocess.entity.PRVNummerPersonKoppl</class>
<class>se.prv.pandora.arendeprocess.entity.Region</class>
<class>se.prv.pandora.arendeprocess.entity.Historik</class>
<class>se.prv.pandora.arendeprocess.entity.Egenskap</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
</persistence-unit>
<!-- <persistence-unit name="PandoraArendeWeb_MSSQL" transaction-type="JTA">
<jta-data-source>jdbc/MSSQL_TEST_XA</jta-data-source>
<class>se.prv.pandora.arendeprocess.entity.PersonSearch</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
</persistence-unit>
-->
</persistence>
persistence.xml files usually contain details related to your database, such as connection strings and their respective user names and passwords including other ORM related information. These details can be placed in other locations so you need not explicitly have one, although having such a file usually makes all persistence related information available in one place which makes looking up certain settings and configurations easier.
This is a sample persistence.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<persistence
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="<PERSISTENCE UNIT NAME>">
<properties>
<!--
<property name="hibernate.ejb.cfgfile" value="/hibernate.cfg.xml"/>
<property name="hibernate.hbm2ddl.auto" value="create"/>
-->
<property name="hibernate.archive.autodetection" value="class, hbm"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.password" value="<PASSWORD>"/>
<property name="hibernate.connection.url" value="jdbc:mysql://<HOST IP ADDRESS>/<DB NAME>"/>
<property name="hibernate.connection.username" value="<USERNAME>"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.c3p0.min_size" value="5"/>
<property name="hibernate.c3p0.max_size" value="20"/>
<property name="hibernate.c3p0.timeout" value="300"/>
<property name="hibernate.c3p0.max_statements" value="50"/>
<property name="hibernate.c3p0.idle_test_period" value="3000"/>
</properties>
</persistence-unit>
</persistence>
The above content was taken from here.
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="AINS" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.tridenthyundai.ains.domainobject.AccessoriesDO</class>
<class>com.tridenthyundai.ains.domainobject.BranchDO</class>
<class>com.tridenthyundai.ains.domainobject.ContactDO</class>
<class>com.tridenthyundai.ains.domainobject.CustomerDO</class>
<class>com.tridenthyundai.ains.domainobject.FinanceDO</class>
<class>com.tridenthyundai.ains.domainobject.InsuranceDO</class>
<class>com.tridenthyundai.ains.domainobject.MessageDO</class>
<class>com.tridenthyundai.ains.domainobject.NotificationDO</class>
<class>com.tridenthyundai.ains.domainobject.ProductDO</class>
<class>com.tridenthyundai.ains.domainobject.ProductPriceDO</class>
<class>com.tridenthyundai.ains.domainobject.ProductSpecDO</class>
<class>com.tridenthyundai.ains.domainobject.ProductVariantDO</class>
<class>com.tridenthyundai.ains.domainobject.PurchaseDO</class>
<class>com.tridenthyundai.ains.domainobject.ServiceCentreDO</class>
<class>com.tridenthyundai.ains.domainobject.ServiceDO</class>
<class>com.tridenthyundai.ains.domainobject.ServiceTypeDO</class>
<class>com.tridenthyundai.ains.domainobject.UserDO</class>
<class>com.tridenthyundai.ains.domainobject.VisitorDO</class>
<!-- shouldn't be valid for java SE per specification, but it works for EclipseLink ... -->
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<!-- For Local Testing -->
<!-- <properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://saptalabs:3306/tridenthyundai" />
<property name="javax.persistence.jdbc.user" value="adminuser" />
<property name="javax.persistence.jdbc.password" value="adminuser" />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="eclipselink.cache.shared.default" value="false"/>
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
<property name="eclipselink.logging.level" value="SEVERE" />
</properties> -->
<!-- For Production -->
</persistence-unit>
</persistence>
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="saptalabs" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.sapta.hr.domainobject.UserDO</class>
<class>com.sapta.hr.domainobject.EmployeeDO</class>
<class>com.sapta.hr.domainobject.AddressDO</class>
<class>com.sapta.hr.domainobject.EmpDetailDO</class>
<class>com.sapta.hr.domainobject.EmpAccDetailDO</class>
<class>com.sapta.hr.domainobject.ProjectDO</class>
<class>com.sapta.hr.domainobject.CustomerDO</class>
<class>com.sapta.hr.domainobject.EmpAssignmentDO</class>
<class>com.sapta.hr.domainobject.EmpAboutDO</class>
<class>com.sapta.hr.domainobject.EmpAchievementsDO</class>
<class>com.sapta.hr.domainobject.EmpEmploymentHistoryDO</class>
<class>com.sapta.hr.domainobject.EmpSportsDO</class>
<class>com.sapta.hr.domainobject.EmpCulturalsDO</class>
<class>com.sapta.hr.domainobject.EmpEducationDO</class>
<class>com.sapta.hr.domainobject.EmpLanguageKnownDO</class>
<class>com.sapta.hr.domainobject.EmpReferencesDO</class>
<class>com.sapta.hr.domainobject.EmpSkillSetDO</class>
<class>com.sapta.hr.domainobject.EmpFamilyBackgroundDO</class>
<class>com.sapta.hr.domainobject.AssetDO</class>
<class>com.sapta.hr.domainobject.AssetTypeDO</class>
<class>com.sapta.hr.domainobject.EmpCTCDO</class>
<class>com.sapta.hr.domainobject.ExpenseDO</class>
<class>com.sapta.hr.domainobject.ExpTypeDO</class>
<class>com.sapta.hr.domainobject.InvoiceDO</class>
<class>com.sapta.hr.domainobject.PayrollDO</class>
<class>com.sapta.hr.domainobject.ProfessionalTaxDO</class>
<class>com.sapta.hr.domainobject.TDSDO</class>
<class>com.sapta.hr.domainobject.VendorDO</class>
<class>com.sapta.hr.domainobject.BillsDO</class>
<class>com.sapta.hr.domainobject.EmpLoseOfPayDO</class>
<!-- shouldn't be valid for java SE per specification, but it works for
EclipseLink ... -->
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<!-- For Local Testing -->
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/hrportal" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="root" />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="eclipselink.cache.shared.default" value="false" />
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode"
value="database" />
<property name="eclipselink.logging.level" value="SEVERE" />
</properties>
</persistence-unit>
</persistence>