Run JPA using Maven and Intellij IDEA 12 -
i have switch on intellij idea , trying test jpa entities using resource_local persistence unit. environment using eclipselink, mysql , maven.
at moment test class performing following call:
entitymanagerfactory factory = persistence.createentitymanagerfactory("app-test");
the persistence unit being detected (if change name in persistence.xml file, error saying unit cannot found). however, if run test getting following errors in console:
exception in thread "main" local exception stack: exception [eclipselink-30005] (eclipse persistence services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.persistenceunitloadingexception exception description: exception thrown while searching persistence archives classloader: sun.misc.launcher$appclassloader@1005354a internal exception: javax.persistence.persistenceexception: exception [eclipselink-28018] (eclipse persistence services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.entitymanagersetupexception exception description: predeployment of persistenceunit [app-test] failed. internal exception: java.lang.nullpointerexception @ org.eclipse.persistence.exceptions.persistenceunitloadingexception.exceptionsearchingforpersistenceresources(persistenceunitloadingexception.java:127) @ org.eclipse.persistence.jpa.persistenceprovider.createentitymanagerfactory(persistenceprovider.java:115) @ javax.persistence.persistence.createentitymanagerfactory(unknown source) @ javax.persistence.persistence.createentitymanagerfactory(unknown source) @ suite.suite.main(suite.java:13) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:601) @ com.intellij.rt.execution.application.appmain.main(appmain.java:120) caused by: javax.persistence.persistenceexception: exception [eclipselink-28018] (eclipse persistence services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.entitymanagersetupexception exception description: predeployment of persistenceunit [app-test] failed. internal exception: java.lang.nullpointerexception @ org.eclipse.persistence.internal.jpa.entitymanagersetupimpl.createpredeployfailedpersistenceexception(entitymanagersetupimpl.java:1541) @ org.eclipse.persistence.internal.jpa.entitymanagersetupimpl.predeploy(entitymanagersetupimpl.java:1532) @ org.eclipse.persistence.internal.jpa.deployment.jpainitializer.callpredeploy(jpainitializer.java:98) @ org.eclipse.persistence.jpa.persistenceprovider.createentitymanagerfactory(persistenceprovider.java:105) ... 8 more caused by: exception [eclipselink-28018] (eclipse persistence services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.entitymanagersetupexception exception description: predeployment of persistenceunit [app-test] failed. internal exception: java.lang.nullpointerexception @ org.eclipse.persistence.exceptions.entitymanagersetupexception.predeployfailed(entitymanagersetupexception.java:221) ... 12 more caused by: java.lang.nullpointerexception @ org.eclipse.persistence.internal.jpa.metadata.metadataproject.hasentity(metadataproject.java:1272) @ org.eclipse.persistence.internal.jpa.metadata.accessors.objects.metadataannotatedelement.isonetomany(metadataannotatedelement.java:610) @ org.eclipse.persistence.internal.jpa.metadata.accessors.classes.classaccessor.buildaccessor(classaccessor.java:594) @ org.eclipse.persistence.internal.jpa.metadata.accessors.classes.classaccessor.addaccessorfields(classaccessor.java:423) @ org.eclipse.persistence.internal.jpa.metadata.accessors.classes.classaccessor.addaccessors(classaccessor.java:395) @ org.eclipse.persistence.internal.jpa.metadata.accessors.classes.classaccessor.preprocess(classaccessor.java:1178) @ org.eclipse.persistence.internal.jpa.metadata.accessors.classes.mappedsuperclassaccessor.preprocess(mappedsuperclassaccessor.java:724) @ org.eclipse.persistence.internal.jpa.metadata.accessors.classes.entityaccessor.preprocess(entityaccessor.java:555) @ org.eclipse.persistence.internal.jpa.metadata.metadataproject.processstage1(metadataproject.java:1649) @ org.eclipse.persistence.internal.jpa.metadata.metadataprocessor.processormmetadata(metadataprocessor.java:531) @ org.eclipse.persistence.internal.jpa.deployment.persistenceunitprocessor.processormetadata(persistenceunitprocessor.java:550) @ org.eclipse.persistence.internal.jpa.entitymanagersetupimpl.predeploy(entitymanagersetupimpl.java:1469) ... 10 more
this persistence.xml
<?xml version="1.0" encoding="utf-8" ?> <persistence version="2.0" 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" xmlns="http://java.sun.com/xml/ns/persistence"> <persistence-unit name="app-test" transaction-type="resource_local"> <provider>org.eclipse.persistence.jpa.persistenceprovider</provider> <exclude-unlisted-classes>false</exclude-unlisted-classes> <properties> <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.driver" /> <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/app" /> <property name="javax.persistence.jdbc.user" value="root" /> <property name="javax.persistence.jdbc.password" value="" /> <property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> <property name="eclipselink.ddl-generation.output-mode" value="database" /> <property name="eclipselink.logging.level" value="finest" /> <property name="eclipselink.logging.level.sql" value="finest" /> <property name="eclipselink.logging.parameters" value="true" /> </properties> </persistence-unit> </persistence>
my pom.xml:
<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <groupid>com.app.entities</groupid> <artifactid>app-entities</artifactid> <version>0.0.1</version> <packaging>jar</packaging> <name>app-entities</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceencoding>utf-8</project.build.sourceencoding> </properties> <dependencies> <dependency> <groupid>org.eclipse.persistence</groupid> <artifactid>eclipselink</artifactid> <version>2.4.0</version> </dependency> <dependency> <groupid>org.eclipse.persistence</groupid> <artifactid>javax.persistence</artifactid> <version>2.0.0</version> </dependency> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <version>4.11</version> </dependency> <dependency> <groupid>com.fasterxml.jackson.core</groupid> <artifactid>jackson-annotations</artifactid> <version>2.1.4</version> </dependency> <dependency> <groupid>com.fasterxml.jackson.core</groupid> <artifactid>jackson-core</artifactid> <version>2.1.4</version> </dependency> <dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <version>5.1.24</version> </dependency> </dependencies> </project>
my folder structure (all entities in src/main/java folder):
i removed project , recreated scratch , working now.
Comments
Post a Comment