質問

私が作り出してしまおうというものは、新しいJava EEプロジェクトを使用hibernate JPA2.0ガラスに魚サーバーです。できるだけ思のあるバイオリソースを設定し、上記のように働いているシームレス?しかしを使用は、発生する持続ユニットを使用し、hibernateはプロバイダかくこのエラー:

javax.persistence.PersistenceException: [PersistenceUnit: DBAppPU] Unable to build EntityManagerFactory
役に立ちましたか?

解決

最初に、インストールHibernateによる支援の アップデートツール (または マニュアルの手順).第二に、JPA2.0 persistence.xml 利用休止していJPAプロバイダ:

<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="MyPu" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <!-- JNDI name of the database resource to use -->
    <jta-data-source>jdbc/__default</jta-data-source>
    <properties>
      <!-- The database dialect to use -->
      <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect" />
      <!-- update database tables at deployment -->
      <property name="hibernate.hbm2ddl.auto" value="update"/>
      <!-- log the generated SQL -->
      <property name="hibernate.show_sql" value="true"/>
    </properties>
  </persistence-unit>
</persistence>

資源

他のヒント

このガイダンスはNetBeans.8.0 IDEでhibernate.4.3.5とEJBとGlassFish.4.0を統合するためのものです。 ネット豆でWebプロジェクトを作成し、プロジェクトに休止jarファイルを追加し、MySQLとのglassfishの構成に関連する他の設定は、私がこの記事では説明しませんので、その後、以下のようにpersistence.xmlファイルを作成する非常に簡単です。

<persistence-unit name="omidashouriPU" transaction-type="Resource_Local">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
            <property name="hibernate.archive.autodetection" value="class"/>
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/YourSchemaName"/>
            <property name="hibernate.connection.username" value="root"/>
            <property name="hibernate.connection.password" value="yourpassword"/>
            <property name="hibernate.show_sql" value="true"/>
    </properties>
</persistence-unit>
構文次のEntityManagerの使用を作成するためのあなたのEJBクラス(@Statelessで注釈を付けていることクラス)では、

EntityManagerFactory emf = Persistence.createEntityManagerFactory("omidashouriPU");
EntityManager em = emf.createEntityManager();
em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(YourEntityObject);
em.getTransaction().end();

As you Know when you are using “transaction-type="Resource_Local", you have to manage the transaction by yourself, mean that, managing of opening and closing the transaction is our responsibility.
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top