私はglassfish、JPAなどにはとても新しいので、設定には本当に問題があります。私がしようとしているのは、永続的なバックエンドを持つ単純なRESTfulなサービスです。私はアプリケーションサーバーとしてglassfish3を使用しており、すでにjersey-libraryで簡単なRESTサービスを展開しています。今、JPA経由でデータベースへのアクセスを提供したいと思います。 GlassfishはJavaDB/derbyとEclipseLinkに同梱されています、そうですか?Glassfishでのpersistence.xml 3.1.1
<?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="myPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDataSource" /> <!-- org.apache.derby.jdbc.EmbeddedDriver -->
<property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/sample;create=true" />
<property name="javax.persistence.jdbc.user" value="APP" />
<property name="javax.persistence.jdbc.password" value="APP" />
<property name="eclipselink.ddl-generation" value="create-tables" />
</properties>
</persistence-unit>
</persistence>
その後、私は私が/ストアSOMのデータにアクセスしたい私のリソース、のフィールドを作成:だから、私は、META-INF内のpersistence.xmlを作成した:-)
それを使用したいです:
@PersistenceUnit(unitName = "myPU")
EntityManagerFactory emf;
しかし、 "EMFは、" 私は私のpersistence.xmlが適切に構成されていないことを推測
:-(常にNULLです
。誰かがヒントを持っている場合、私は間違っていると本当にうれしいでしょう...
ありがとう!
persistence.xmlがプロジェクト内のどこにあるかは関係ありません。それはapp.war:/WEB-INF/classes/META-INF/persistence.xmlにあるはずですが、app.warで終わっていました。/META-INF/persistence.xmlは容疑者です。 –