私はこの構造を持っています:
- xptoapp
- xptoapp-main
- xptoapp コア
- xptoapp ドメイン
パッケージ「xptoapp-main」には、次のような pom.xml があります。
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org /xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org /2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.xpto</groupId>
<artifactId>xptoapp</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>xptoapp-main</artifactId>
<name>xptoapp-main</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.xpto</groupId>
<artifactId>xptoapp-domain</artifactId>
<version>${version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.xpto</groupId>
<artifactId>xptoapp-core</artifactId>
<version>${version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
プロジェクト「xptoapp-domain」内に META-INF/persistence.xml があります。プロジェクト 'xptoapp-app' (フォルダー META-INF ) 内に persistence.xml を配置する必要がありますか?
「java -jar xpto-app.jar」を実行しようとすると、例外が発生しました:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: javax.persistence.PersistenceException: Unable to configure EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:385)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at com.xpto.domain.persistence.PersistenceManager.<init>(PersistenceManager.java:14)
at com.xpto.app.App.main(App.java:30)
... 5 more
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(Unknown Source)
at org.hibernate.ejb.packaging.JarVisitorFactory.getJarURLFromURLEntry(JarVisitorFactory.java:57)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:351)
... 10 more
私の場合、どのようにJPAを使用できますか? なぜこの例外が発生するのですか?
persistence.xml
<?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_2_0.xsd"
version="2.0">
<persistence-unit name="xptoapp" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.xpto.domain.entity.Account</class>
<class>com.xpto.domain.entity.Transfer</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:mem:xptoapp" />
<property name="javax.persistence.jdbc.user" value="sa" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.show_sql" value="false" />
</properties>
</persistence-unit>
</persistence>