Can't connect to JDBC From persistence.xml - java

I have plain java class book annotated as Entity for jpa.
I configure persistence xml, but i have big stack trace with exception which i don't understand. Also, i can't find jdbc package in javax.persistence. What do me?
This is my Entity
package Java.JPA;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
#Entity
public class Book
{
#Id #GeneratedValue
private long id;
private String title;
public Book()
{
}
public Book(String title) {
this.title = title;
}
public String getTitle()
{
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
this is my main class
package Java;
import Java.JPA.Book;
import java.sql.SQLException;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
public class main
{
public static void main(String[] args) throws SQLException, ClassNotFoundException {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("example");
EntityManager em = emf.createEntityManager();
Book book = new Book("TestJPA");
EntityTransaction tx = em.getTransaction();
tx.begin();
em.persist(book);
tx.commit();
em.close();
emf.close();
}
}
and this is my persistence.xml
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="example">
<!--<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>-->
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>Java.JPA.Book</class>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/studyJPA"/>
<property name="javax.persistence." value="root"/>
<property name="javax.persistence.jdbc.password" value="root"/>
</properties>
</persistence-unit>
</persistence>
stack trace:
"C:\Program Files\Java\jdk1.8.0_92\bin\java" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2017.3.2\lib\idea_rt.jar=55859:C:\Program Files\JetBrains\IntelliJ IDEA 2017.3.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_92\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\rt.jar;C:\Tomcat\apache-tomcat-9.0.7\lib\servlet-api.jar;C:\Users\Anton\Desktop\study\target\classes;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\javaee-api-7.0-1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\jsp-api.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomcat-api.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\servlet-api.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\el-api.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\jasper.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\catalina.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\ecj-4.6.3.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\jasper-el.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\jaspic-api.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomcat-jni.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\catalina-ha.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\serp-1.15.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomcat-dbcp.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomcat-jdbc.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomcat-util.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\xalan-2.7.2.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\catalina-ant.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\hawtbuf-1.11.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\howl-1.0.1-1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\hsqldb-2.3.2.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\jasypt-1.9.2.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\mimepull-1.9.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\neethi-3.0.3.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\wsdl4j-1.6.3.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\xmlsec-2.0.6.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\joda-time-2.7.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openjpa-2.4.3.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\stax-ex-1.7.4.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomcat-coyote.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\websocket-api.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\activation-1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\bval-jsr-1.1.2.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\jaxb-api-2.3.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\stax-api-1.0-2.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomcat-i18n-es.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomcat-i18n-fr.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomcat-i18n-ja.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\bval-core-1.1.2.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\catalina-tribes.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\commons-cli-1.2.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cryptacular-1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-core-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\jaxb-core-2.3.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\jaxb-impl-2.3.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\stax2-api-3.1.4.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\sxc-runtime-0.8.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\commons-lang-2.6.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\saaj-impl-1.3.23.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\serializer-2.7.2.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\slf4j-api-1.7.21.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomcat-util-scan.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomcat-websocket.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomee-jdbc-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\xbean-naming-4.9.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\xml-resolver-1.2.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\commons-dbcp2-2.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\commons-lang3-3.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\commons-pool2-2.3.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-api-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-cxf-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-javaagent.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-jee-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\sxc-jaxb-core-0.8.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomee-jaxrs-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\xbean-reflect-4.9.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\activemq-ra-5.14.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\commons-codec-1.10.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-wsdl-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\java-support-7.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\johnzon-core-1.0.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\myfaces-api-2.2.12.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-core-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-ejbd-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-hsql-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-http-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-rest-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\slf4j-jdk14-1.7.21.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomee-common-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomee-loader-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomee-webapp-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\wss4j-policy-2.1.9.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\bcprov-jdk15on-1.60.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\commons-logging-1.2.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\johnzon-jaxrs-1.0.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\johnzon-jsonb-1.0.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\myfaces-impl-2.2.12.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\opensaml-core-3.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomee-mojarra-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomee-myfaces-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\catalina-storeconfig.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\commons-digester-1.8.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\commons-jcs-core-2.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\johnzon-mapper-1.0.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-client-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-cxf-rs-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-loader-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-server-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\swizzle-stream-1.6.2.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomee-catalina-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\wss4j-bindings-2.1.9.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\xmlschema-core-2.2.3.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\activemq-protobuf-1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-ws-addr-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openwebbeans-ee-1.7.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\xbean-asm6-shaded-4.9.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\xbean-bundleutils-4.9.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\activemq-broker-5.14.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\activemq-client-5.14.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\commons-jcs-jcache-2.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-security-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openwebbeans-ejb-1.7.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openwebbeans-jsf-1.7.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openwebbeans-spi-1.7.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openwebbeans-web-1.7.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\commons-beanutils-1.9.3.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-rs-client-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-ws-policy-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\opensaml-saml-api-3.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\opensaml-soap-api-3.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openwebbeans-el22-1.7.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openwebbeans-impl-1.7.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomee-webservices-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\woodstox-core-asl-4.4.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\xbean-finder-shaded-4.9.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-management-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\geronimo-connector-3.1.4.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\opensaml-saml-impl-3.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\opensaml-xacml-api-3.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\commons-collections-3.2.2.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-ws-security-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-webservices-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\opensaml-xacml-impl-3.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\opensaml-xmlsec-api-3.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\activemq-jdbc-store-5.14.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-bindings-xml-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\geronimo-transaction-3.1.4.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\mbean-annotation-api-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\opensaml-profile-api-3.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\opensaml-xmlsec-impl-3.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\quartz-openejb-shade-2.2.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-bindings-soap-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-rs-json-basic-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-security-saml-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\geronimo-jsonb_1.0_spec-1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-cxf-transport-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-jee-accessors-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\opensaml-security-api-3.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\taglibs-standard-impl-1.2.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\taglibs-standard-spec-1.2.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\wss4j-ws-security-dom-2.1.9.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\activemq-kahadb-store-5.14.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-frontend-jaxrs-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-frontend-jaxws-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\opensaml-security-impl-3.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openwebbeans-ee-common-1.7.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\wss4j-ws-security-stax-2.1.9.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\batchee-jbatch-0.4-incubating.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-frontend-simple-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-transports-http-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-jpa-integration-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\opensaml-xacml-saml-api-3.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\taglibs-standard-jstlel-1.2.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-databinding-jaxb-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-rs-security-cors-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-rs-security-jose-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\opensaml-xacml-saml-impl-3.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\wss4j-ws-security-common-2.1.9.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\activemq-openwire-legacy-5.14.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-rs-security-oauth2-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-rs-extension-search-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\wss4j-ws-security-policy-stax-2.1.9.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-rs-extension-providers-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-rs-security-jose-jaxrs-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-rs-service-description-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\geronimo-javamail_1.4_mail-1.9.0-alpha-2.jar;C:\Users\Anton\.m2\repository\mysql\mysql-connector-java\8.0.12\mysql-connector-java-8.0.12.jar;C:\Users\Anton\.m2\repository\com\google\protobuf\protobuf-java\2.6.0\protobuf-java-2.6.0.jar;C:\Users\Anton\.m2\repository\org\hibernate\hibernate-core\5.3.6.Final\hibernate-core-5.3.6.Final.jar;C:\Users\Anton\.m2\repository\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;C:\Users\Anton\.m2\repository\javax\persistence\javax.persistence-api\2.2\javax.persistence-api-2.2.jar;C:\Users\Anton\.m2\repository\org\javassist\javassist\3.23.1-GA\javassist-3.23.1-GA.jar;C:\Users\Anton\.m2\repository\net\bytebuddy\byte-buddy\1.8.17\byte-buddy-1.8.17.jar;C:\Users\Anton\.m2\repository\antlr\antlr\2.7.7\antlr-2.7.7.jar;C:\Users\Anton\.m2\repository\org\jboss\spec\javax\transaction\jboss-transaction-api_1.2_spec\1.1.1.Final\jboss-transaction-api_1.2_spec-1.1.1.Final.jar;C:\Users\Anton\.m2\repository\org\jboss\jandex\2.0.5.Final\jandex-2.0.5.Final.jar;C:\Users\Anton\.m2\repository\com\fasterxml\classmate\1.3.4\classmate-1.3.4.jar;C:\Users\Anton\.m2\repository\javax\activation\javax.activation-api\1.2.0\javax.activation-api-1.2.0.jar;C:\Users\Anton\.m2\repository\dom4j\dom4j\1.6.1\dom4j-1.6.1.jar;C:\Users\Anton\.m2\repository\org\hibernate\common\hibernate-commons-annotations\5.0.4.Final\hibernate-commons-annotations-5.0.4.Final.jar;C:\Users\Anton\.m2\repository\org\eclipse\persistence\javax.persistence\2.2.1\javax.persistence-2.2.1.jar;C:\Users\Anton\.m2\repository\org\eclipse\persistence\org.eclipse.persistence.jpa\2.7.3\org.eclipse.persistence.jpa-2.7.3.jar;C:\Users\Anton\.m2\repository\org\eclipse\persistence\org.eclipse.persistence.asm\2.7.3\org.eclipse.persistence.asm-2.7.3.jar;C:\Users\Anton\.m2\repository\org\eclipse\persistence\org.eclipse.persistence.antlr\2.7.3\org.eclipse.persistence.antlr-2.7.3.jar;C:\Users\Anton\.m2\repository\javax\json\javax.json-api\1.1.2\javax.json-api-1.1.2.jar;C:\Users\Anton\.m2\repository\org\eclipse\persistence\org.eclipse.persistence.jpa.jpql\2.7.3\org.eclipse.persistence.jpa.jpql-2.7.3.jar;C:\Users\Anton\.m2\repository\org\eclipse\persistence\org.eclipse.persistence.core\2.7.3\org.eclipse.persistence.core-2.7.3.jar" Java.main
91 INFO [main] openjpa.Runtime - OpenJPA dynamically loaded the class enhancer. Any classes that were not enhanced at build time will be enhanced when they are loaded by the JVM.
121 INFO [main] openjpa.Runtime - Starting OpenJPA 2.4.3
Exception in thread "main" <openjpa-2.4.3-r422266:1833086 fatal user error> org.apache.openjpa.persistence.ArgumentException: The persistence provider is attempting to use properties in the persistence.xml file to resolve the data source. A Java Database Connectivity (JDBC) driver or data source class name must be specified in the openjpa.ConnectionDriverName or javax.persistence.jdbc.driver property. The following properties are available in the configuration: "org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl#2655aabb".
at org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:71)
at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory(JDBCConfigurationImpl.java:850)
at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(JDBCConfigurationImpl.java:603)
at org.apache.openjpa.jdbc.meta.MappingRepository.endConfiguration(MappingRepository.java:1520)
at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:535)
at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:460)
at org.apache.openjpa.lib.conf.PluginValue.instantiate(PluginValue.java:121)
at org.apache.openjpa.conf.MetaDataRepositoryValue.instantiate(MetaDataRepositoryValue.java:68)
at org.apache.openjpa.lib.conf.ObjectValue.instantiate(ObjectValue.java:83)
at org.apache.openjpa.conf.OpenJPAConfigurationImpl.newMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:973)
at org.apache.openjpa.conf.OpenJPAConfigurationImpl.getMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:964)
at org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:642)
at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:202)
at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:154)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:226)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:153)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:59)
at Java.main.main(main.java:15)
Process finished with exit code 1
in dependencies pom.xml there are hibernate and mysql driver. Also, i import javaee-api-7.0-1.jar, servlet-api.jar and jsp-api.jar from tomcat's directory. Please help. More than several hours i trying to solve it. I will be grateful!
this is my java ee jar file. There is not jdbc package or another files with name "jdbc"
enter image description here
maybe, i downloaded wrong tomcat ee. If this is true, give me a link for download correct version.
I don't know what happened, but i have new exception
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/geronimo/osgi/locator/ProviderLocator
at javax.persistence.spi.PersistenceProviderResolverHolder$DefaultPersistenceProviderResolver.getPersistenceProviders(PersistenceProviderResolverHolder.java:108)
at javax.persistence.Persistence.getProviders(Persistence.java:275)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:88)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:72)
at Java.main.main(main.java:14)
Caused by: java.lang.ClassNotFoundException: org.apache.geronimo.osgi.locator.ProviderLocator
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 5 more
It's magic:) Now i have a question. How to fix that?

<persistence>
<persistence-unit name="manager1" transaction-type="RESOURCE_LOCAL">
<class>org.hibernate.ejb.test.Apple</class>
<class>org.hibernate.ejb.test.Distributor</class>
<class>org.hibernate.ejb.test.Fruit</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver"/>
<property name="javax.persistence.jdbc.user" value=""/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:."/>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/
<property name="hibernate.max_fetch_depth" value="3"/>
<property name="hibernate.ejb.classcache.org.hibernate.ejb.test.Item"
value="read-write"/>
<property name="hibernate.ejb.collectioncache.org.hibernate.ejb.test.Item.distributors"
value="read-write, RegionName"/>
</properties>
</persistence-unit>
</persistence>

Related

Could not find any META-INF/persistence.xml file in the classpath, but i've added it

I am trying to add JPA to my project, but always getting those errors:
keycloak_1 | 17:28:43,494 INFO [org.hibernate.jpa.boot.internal.PersistenceXmlParser] (default task-2) HHH000318: Could not find any META-INF/persistence.xml file in the classpath
keycloak_1 | 17:28:43,495 ERROR [org.keycloak.services.error.KeycloakErrorHandler] (default task-2) Uncaught server error: javax.persistence.PersistenceException: No Persistence provider for EntityManager named SQL
But when i try to initialise my entity manager:
HashMap<String, String> properties = new HashMap<>();
properties.put("javax.persistence.jdbc.driver", configMap.getFirst(CONFIG_KEY_JDBC_URL));
properties.put("javax.persistence.jdbc.url", configMap.getFirst(CONFIG_KEY_JDBC_URL));
properties.put("javax.persistence.jdbc.user", configMap.getFirst(CONFIG_KEY_DB_USERNAME));
properties.put("javax.persistence.jdbc.password", configMap.getFirst(CONFIG_KEY_DB_PASSWORD));
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory(
"SQL",
properties
);
EntityManager entityManager = entityManagerFactory.createEntityManager();
I am receiving those errors, but i can't understand how it's possible then i am clearly added that file to my .jar.
Persistence.xml content is :
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd"
version="2.2">
<persistence-unit name="SQL" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="javax.persistence.jdbc.driver" value=""/>
<property name="javax.persistence.jdbc.url" value=""/>
<property name="javax.persistence.jdbc.user" value=""/>
<property name="javax.persistence.jdbc.password" value=""/>
</properties>
</persistence-unit>
</persistence>
Structure of project and compiled jar is visible here (persistence content is changed to 2.2 version to mentioned before):
What am i doing wrong?
Update:
Even find command returns that file exists in a correct directory:
➜ sql-sync-spi find . -type f -name "persistence.xml"
./build/resources/main/META-INF/persistence.xml
./src/main/resources/META-INF/persistence.xml
More updates:
I've tried to copy persistence.xml from another project:
<?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="user-storage-jpa-example">
<jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
<class>org.keycloak.quickstart.storage.user.UserEntity</class>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="false" />
</properties>
</persistence-unit>
</persistence>
And on service startup i've received fatal error:
07:03:02,188 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "sql-sync-spi-1.0-SNAPSHOT.jar")]) - failure description: {
"WFLYCTL0412: Required services that are not installed:" => ["jboss.naming.context.java.jboss.datasources.ExampleDS1"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"jboss.persistenceunit.\"sql-sync-spi-1.0-SNAPSHOT.jar#sql\".__FIRST_PHASE__ is missing [jboss.naming.context.java.jboss.datasources.ExampleDS]",
"jboss.persistenceunit.\"sql-sync-spi-1.0-SNAPSHOT.jar#sql\" is missing [jboss.naming.context.java.jboss.datasources.ExampleDS1]"
]
}
So at least part of the project sure sees persistence.xml file and tries to read it. Then i've changed xml back to my settings, and again i have no error on startup but again no file exists in classpath on entity manager init attempt.
This is more of a comment than an answer since there's not enough room in the comment section and I haven't verified any of this.
First of all, I'd define a new DataSource on your Keycloak server. See: Relational Database Setup.
Your dependencies section of build.gradle should then look somewhat similar to:
dependencies {
compileOnly 'org.keycloak:keycloak-server-spi'
compileOnly 'org.keycloak:keycloak-common'
implementation 'org.apache.commons:commons-lang3:3.12.0'
compileOnly 'org.hibernate.javax.persistance:hibernate-jpa-2.1-api:1.0.0.Final'
compileOnly 'org.jboss.spec.javax.ejb:jboss-ejb-api_3.2_spec:1.0.0.Final'
compileOnly platform('org.wildfly.bom:wildfly-javaee8:14.0.1.Final')
compileOnly platform('org.keycloak.bom:keycloak-spi-bom:15.0.1')
}
Your persistence.xml should change since we defined a DataSource on Keycloak:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="yourDataSource">
<jta-data-source>your_DS_name</jta-data-source>
<!-- List your entities here. For example: -->
<class>com.rmndbrvn.sqlsyncspi.UserEntity</class>
</persistence-unit>
</persistence>
You can then get an instance to an EntityManager in your code like this:
#PersistenceContext(unitName = "yourDataSource")
EntityManager em;

ClassCastException while using find() for javax.persistence.EntityManager

While attempting to retrieve an Entity from a Database, using JPA's EntityManager, I am getting a ClassCastException that references two identical Classes. After reading other posts/articles, I suspect that the application using 2 different Class Loaders on the same Class type may be the culprit. Unfortunately, I have no idea how to verify nor correct this. Could someone help shine some light on this situation and its solution?
Entity Member.java
package com.example.mysql_flyway_database.entities;
import javax.persistence.*;
#Entity
#Table(name = "_member_")
public class Member {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "id")
private Integer memberId;
#Column(name = "member_name")
private String memberName;
public Integer getMemberId() {
return memberId;
}
... // other getter/setter methods
}
persistence.xml - stored in /resources/META-INF/, in case this matters
<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="Member" transaction-type="RESOURCE_LOCAL">
<class>com.example.mysql_flyway_database.entities.Member</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url"
value="jdbc:mysql://localhost:3306/JDND_C3"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="Keep1Moving2Forward3!"/>
</properties>
</persistence-unit>
</persistence>
MyApplication
...
private static void readMembersAsEntities(EntityManagerFactory factory) {
EntityManager manager = factory.createEntityManager();
manager.getTransaction().begin();
Member member = manager.find(Member.class, 1);
System.out.println(String.format("Member %s was found", member.getMemberName()));
}
...
Here is the log:
Exception in thread "restartedMain" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.ClassCastException: com.example.mysql_flyway_database.entities.Member cannot be cast to com.example.mysql_flyway_database.entities.Member
at com.example.mysql_flyway_database.MysqlFlywayDatabaseApplication.readMembersAsEntities(MysqlFlywayDatabaseApplication.java:51)
at com.example.mysql_flyway_database.MysqlFlywayDatabaseApplication.main(MysqlFlywayDatabaseApplication.java:42)
... 5 more
Note:
This is quite similar to the issue underlined here:
JPA class loading issue with Hibernate.
Disclosure: I am fairly new to Spring and its plugins/dependencies (currently learning), so I am a bit lost on the provided solution described in the post mentioned. Regarding the solution mentioned in the provided post: In my project, I do not see /WEB-INF/lib.
Any help would be greatly appreciated.

Injecting EntityManager returns null after Jboss/Wildfly migration

My application is running perfectly fine in JBoss AS 5.1.0. My goal is to migrate it to Wildfly 10.
Below is my persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="ApplicationPersistenceUnit">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/MySQL_DS</jta-data-source>
<jar-file>application_db_interface.jar</jar-file>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="jboss.entity.manager.jndi.name" value="java:/ApplicationPersistenceUnit"/>
<property name="jboss.entity.manager.factory.jndi.name" value="java:/ApplicationPersistenceUnitFactory"/>
</properties>
</persistence-unit>
</persistence>
Below is my transaction manager class;
public class TransactionManager implements TransactionManagerI {
#PersistenceContext(unitName="ApplicationPersistenceUnit")
private EntityManager em;
...
}
I also try to use lookup but it still returns null;
public Session getSession() throws DAOException {
..
em = (EntityManager) new InitialContext().lookup("java:/ApplicationPersistenceUnit");
..
}
Below is the project schema;
->application.ear
->application.ear/application.war
->application.ear/db.jar
->application.ear/db.jar/META-INF/persistence.xml
I looked into other solutions and try one by one but couldn't figure out mine yet. I can provide more info if you need.
UPDATE: I check JNDI view from wildfly admin console. I don't see ApplicationPersistenceUnit there. It looks like server doesn't bind my persistence.xml file. I am now trying to figure out this problem.

Hibernate with Sql Server fail for nvarchar field with "No Dialect mapping..."

I'm using Hibernate's JPA-Implementation to access our SQL Server 2012 database.
When trying to select a nvarchar field in a native query, I get an exception "No Dialect mapping for JDBC type: -9".
It looks much like No Dialect mapping for JDBC type: -9 with Hibernate 4 and SQL Server 2012 or No Dialect mapping for JDBC type: -9 but I couldn't find a solution for me there (both are not using JPA).
My database setup:
CREATE TABLE NvarcharExample(
exampleField nvarchar(20) PRIMARY KEY
)
INSERT INTO NvarcharExample(exampleField) VALUES ('hello')
My code:
import java.io.IOException;
import javax.persistence.*;
#Entity
class NvarcharExample {
#Id
public String exampleField;
}
public class NvarcharTest {
public static void main(String[] args) throws IOException, InterruptedException {
String queryString = "SELECT e.exampleField FROM NvarcharExample e";
// establish connection
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("persistenceUnit");
try {
EntityManager entityManager = entityManagerFactory.createEntityManager();
// access data using JPQL
entityManager.createQuery(queryString).getResultList(); // works
// access data using SQL (native query)
entityManager.createNativeQuery(queryString).getResultList(); // fails
} finally {
entityManagerFactory.close();
}
}
}
My persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="persistenceUnit">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<!-- database connection settings -->
<property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:sqlserver://<servername>:<port>;databaseName=<databasename>" />
<property name="javax.persistence.jdbc.user" value="<user>" />
<property name="javax.persistence.jdbc.password" value="<password>" />
</properties>
</persistence-unit>
</persistence>
With sql logging enable, I get this output in my console
select nvarcharex0_.exampleField as col_0_0_ from NvarcharExample nvarcharex0_
SELECT e.exampleField FROM NvarcharExample e
I'm using
hibernate-core-4.3.10.Final.jar
hibernate-entitymanager-4.3.10.Final.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar
hibernate-commons-annotations-4.0.5.Final.jar
sqljdbc41.jar
What I've tried:
using a varchar instead of nvarchar makes it work, but I need nvarchar
using jpql instead of sql works (see my example code), but I need a native query
I tried sqljdbc4.jar in Version 4.0 and 4.1 and I tried sqljdbc41.jar
I head about subclassing the SQL Server Dialect class, but did not have any success with that
I added <property name="dialect" value="org.hibernate.dialect.SQLServerDialect" /> to my persistence.xml (right behind the password property)
I added <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" /> to my persistence.xml
I changed the persistence provider to <provider>org.hibernate.ejb.HibernatePersistence</provider>
Using #Nationalized attribute helped me to map String to nvarchar for MS SQL 2012 without dialect subclassing.
At the same time setting the hibernate.use_nationalized_character_data property to true did not worked for me.
For futher information watch docs National Character Types.
I was able to resolve that issue by subclassing the SQLServerDialect:
package packagename;
import java.sql.Types;
public class SqlServerDialectWithNvarchar extends org.hibernate.dialect.SQLServerDialect {
public SqlServerDialectWithNvarchar() {
registerHibernateType(Types.NVARCHAR, 4000, "string");
}
}
and referencing it in my persistence.xml:
<property name="hibernate.dialect" value="packagename.SqlServerDialectWithNvarchar" />
PS: It seems to be fixed with hibernate 5.1 according to this ticket: https://hibernate.atlassian.net/browse/HHH-10183

Embedded Java DB from within Felix?

I assume there's a way to use an embedded Java DB instance within a standalone Felix 4.0.2 OSGi box. However I can't seem to find any clues as to how I should setup the whole thing: What implementation bundles should I use? How should I set it up?
I tried quite a few things, including getting the dedicated bundles from a glassfich 3.1.2 install, but whatever I do no persistence manager is registered by the framework to provide my app with.
My code otherwise follows all academical precepts, with a a ServiceTracker being registered to find out about EntityManagerFactory registrations, but none is found...
Here's my persistence.xml file:
<?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="com.julianware.toolbox.logbacktracker.pu"
transaction-type="RESOURCE_LOCAL">
<!-- mapping-file>META-INF/maintenance_orm.xml</mapping-file>
<mapping-file>META-INF/vehicle_orm.xml</mapping-file -->
<class>com.julianware.toolbox.logbacktracker.pu.LoggerEvent</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:derby:database;create=true" />
<property name="javax.persistence.jdbc.user" value="felix" />
<property name="javax.persistence.jdbc.password" value="felix" />
</properties>
</persistence-unit>
And my Activator's start() method:
public void start(final BundleContext context) throws Exception {
Filter filter = context.createFilter(String.format("(&(%s=%s)(%s=%s))",
OBJECTCLASS, EntityManagerFactory.class.getName(),
EntityManagerFactoryBuilder.JPA_UNIT_NAME, "com.julianware.toolbox.logbacktracker.pu")
);
entityManagerFactoryTracker = new ServiceTracker(context, filter, new ServiceTrackerCustomizer() {
#Override
public void removedService(ServiceReference reference, Object service) {}
#Override
public void modifiedService(ServiceReference reference, Object service) {}
#Override
public Object addingService(ServiceReference reference) {
logger.debug("Found Entity Manager Service reference.");
entityManagerFactory = (EntityManagerFactory) context.getService(reference);
return entityManagerFactory;
}
});
entityManagerFactoryTracker.open();
}
Last, I'm on JDK 7. Java DB implementation is that of the jdk install.
Does anyone know anything?
Mighty thanks.
Julian
I'm not sure, but you could try Derby from Maven Central. It should contain the correct OSGi meta data.

Categories